Skip to main content
CodeOath

Coding Tier 1: problem solving in Python · Chapter 9

Counting, positions and one-pass tricks

About this chapter

Many coding-interview questions are variations on a few moves: count with a dictionary, remember what has been seen, and carry a running value through a single pass. This chapter practises those moves on eleven small problems drawn from one scanner log, from repeated entries and grouping by a signature to a missing number, products without division and rotating a list in place.

Who it is for: Students preparing for coding rounds who can write loops and use dictionaries in Python and want a small set of patterns that solve many problems.

You will be able to

  • Use a dictionary of counts to answer questions about repeated items.
  • Record the positions where an item appears while scanning the input once.
  • Group items that belong together by building a signature for each one.
  • Find a majority item or a missing number without a counting table.
  • Solve a product-without-division or rotate-in-place problem and test it on empty and single-item inputs.

The key idea: Most of these problems look hard until the question is rephrased as something to remember while moving through the input once. The remembered thing is a count, a position, a signature or a running value, and picking which one is most of the work.

In this chapter

  1. A log that answers questions
  2. Count first, ask later
  3. Where did it happen?
  4. Grouping by a signature
  5. Voting without a table
  6. The number that went missing
  7. Products without division
  8. Moving things in place
  9. Where each one goes wrong

Locked: needs a plan

You can read chapter 1 free. Chapter 9 is the next one.

What you can do now, free: re-read chapter 1 and try its problems.

What a plan gives you: all chapters of the track you pick and their checks. Starter is ₹229 a month or ₹1,699 a year. It renews until you cancel, and you can cancel any time. Paid plans open at launch.

Why is this locked?

Chapter 1 of every track is free, so you can see how the track reads. The rest of a track and its checks come with a plan, or open as you pass each chapter's check.

The price is for one period, a month or a year. A plan renews until you cancel.

Back to the track