Bird
0
0

A Board class stores pieces in a 2D array but does not check bounds before accessing. What problem can occur when accessing board[-1][0]?

medium📝 Analysis Q7 of 15
LLD - Design — Chess Game
A Board class stores pieces in a 2D array but does not check bounds before accessing. What problem can occur when accessing board[-1][0]?
AAutomatically resizes the board
BReturns the last row's first piece
CReturns null without error
DAn index out of bounds error or exception
Step-by-Step Solution
Solution:
  1. Step 1: Understand array indexing rules

    Negative indices are invalid in most languages and cause errors.
  2. Step 2: Consequence of no bounds check

    Accessing negative index without check triggers index out of bounds error.
  3. Final Answer:

    An index out of bounds error or exception -> Option D
  4. Quick Check:

    Negative index access = error [OK]
Quick Trick: Always check array bounds before access [OK]
Common Mistakes:
  • Assuming negative index wraps around
  • Expecting null return without error
  • Thinking board auto-resizes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes