Open or Closed: A Door After the First Y People
Updated
Problem statement
A row of 100 doors, numbered 1 to 100, starts with every door closed. For each k in turn, person k walks the row and switches the state of every k-th door (doors k, 2k, 3k, … up to 100): an open door is closed and a closed door is opened.
Return true if door door is open after persons 1 through person have all walked the row, and false if it is closed.
Function
isDoorOpen(door: int, person: int) → booleanExamples
Example 1
door = 36person = 100return = trueDoor 36 is touched by persons 1, 2, 3, 4, 6, 9, 12, 18 and 36: nine times, an odd number, so it ends open.
Example 2
door = 12person = 5return = falsePersons 1 to 5 reach door 12 at 1, 2, 3 and 4 (5 does not divide 12): four touches, an even number, so it is closed again.
Example 3
door = 7person = 1return = trueOnly person 1 has passed, and person 1 opens every door, so the answer is true.
Constraints
1 <= door <= 1001 <= person <= 100
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Generate an Unbiased Bit from a Biased CoinGoogle · ONSITE INTERVIEWGoogle interview questions
- Moving Cost by Volume and CategoryWayfair · ONSITE INTERVIEWWayfair interview questions
- 100 DoorsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Clock Hand Angle with Subsecond PrecisionScale AI · ONSITE INTERVIEWScale AI interview questions
- Recover the Initial Mango PileLSEG · ONSITE INTERVIEWLSEG interview questions
- Estimate Pi from Sampled PointsJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Add Two Numeric Strings with CarryZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
- Three- and Five-liter Jug PlanXilinx · ONSITE INTERVIEWXilinx interview questions
- Babysitter Quote with Hourly RatesUpstart · ONSITE INTERVIEWUpstart interview questions
- Expected Value of Modified DiceJane Street · ONSITE INTERVIEWJane Street interview questions
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences