DEV Community

Saranya R
Saranya R

Posted on

First & Last Occurrences

Approach Explanation (ノ◕ヮ◕)ノ*:・゚✧

  1. I wrote two helper functions, one to find the first_occurrence and one to find the last_occurrence using binary search.
  2. Each function returns an index (or -1 if not found).
  3. In the final return, I must call these functions with () so they execute and give results.
  4. Without (), Python just returns the function reference, not its output.

Method Used: (〜 ̄▽ ̄)〜

  • Binary search twice
  • Function calls
  • Efficient runtime

Top comments (0)