Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

0-based indexing vs 1-based indexing

Revision en1, by dholakpur_wala_raju, 2023-12-26 21:54:22

A genuine question to all problem setters: why do most of the questions have $$$1$$$-based indexing and not $$$0$$$-based indexing (for instance, permutations, $$$[l,r]$$$ range queries, graph nodes are mostly $$$1$$$ to $$$n$$$ instead of $$$0$$$ to $$$n-1$$$. In my humble opinion, having $$$0$$$-based indexing just helps in writing a much cleaner code i.e. a slightly simplified implementation, like I can create an array of length $$$n$$$ instead of $$$n+1$$$, since computer uses $$$0$$$-based indexing and hence $$$1$$$-based indexing adds an unnecessary offset of $$$1$$$. This offset is most likely not the intention of the problem setter to judge the contestant on his/her problem-solving skills. However, I will mention that $$$1$$$-based indexing looks cleaner to human eyes but with respect to programming perspective, I really don't see any point other than missing it and getting an unnecessary WA.

Tags 1-based, 0-based, 1-indexed, 0-indexed

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English dholakpur_wala_raju 2023-12-26 21:54:22 893 Initial revision (published)