The Phone Screen
- Treat the short problem on a two-problem phone screen as scored work, and trace its edge inputs by hand
- Seat theater guests greedily with a yes-or-no early exit, then count empty runs when the seats stream in
- Turn Bulb Switcher into a perfect-squares count, and list the bulbs left on in O(sqrt n)
- Validate a config value's parentheses with a stack, then with a single depth counter in O(1) space
LinkedIn's technical phone screen runs about an hour, and it often has two problems. One of them is usually a short warm-up next to a heavier problem. Bulb Switcher, Can Place Flowers set up as theater seating, and Valid Parentheses set up as a config validator keep turning up in that slot.
Interviewers expect the same clean code and hand trace on the warm-up as on the heavier problem, and candidates have been turned down after solving both. In the three problems below, the bugs sit at the edges, like the end seats of the theater row or a close paren that arrives before any opener.
One idea per problem
None of these needs a clever data structure. Each needs one observation that replaces a simulation with a count. Bulb Switcher reduces to counting perfect squares, because each bulb flips once per divisor. The seating row needs one greedy pass that takes the first legal empty seat. With a single bracket type, the validator's stack holds nothing beyond its height, so a counter can replace it. The follow-up usually asks you to defend that observation or extend it.
State the observation before the code. "Every bulb flips once per divisor, and only perfect squares have an odd count" answers Bulb Switcher in a sentence. Saying it first lets the interviewer agree before you type, and it gives your hand trace something to check against.
Asked at LinkedIn
Three warm-ups, in rough order of how often they come up. Each test case is the function's arguments as a JSON array and the expected return. Give each one a timed pass in the editor, dry-run it, and then read the walkthrough for the follow-up.
Can Place Flowers: Seating Strangers in a Theater
Problem
seats where 1 marks an occupied seat and 0 an empty one. Nobody wants to sit next to another person, so a new guest may only take an empty seat whose left and right neighbors (where they exist) are both empty, and every guest you seat counts as a neighbor for the guests after them. Given an integer people, return true if you can seat that many new guests and false otherwise.The row as given may already have guests sitting side by side; the rule binds only the people you seat.
seats holds at least one seat, and people is at least 0.Input encoding. Each test case is a JSON array
[seats, people]. The function returns a boolean.Seat 2 is the only empty seat with both neighbors empty, so exactly one guest fits.
Seats 0 and 4 sit at the ends of the row, so each needs only its one inner neighbor empty.
Scan left to right and seat a guest at the first empty seat whose neighbors are both free. Remember the index of the nearest occupied seat to the left, original or new, so the input never changes, and stop as soon as the count reaches people.
Can Place Flowers: Seating Strangers in a Theater
Click "Run" to execute your code
boolean canSeatPeople(List seats, int numberOfPlace) . The return type tells you the answer is yes or no against a target, so the scan can stop once the count reaches it. Explain out loud why the greedy works: the first legal seat in an empty run never fits fewer guests than a later pick would. The bugs are usually at seat 0 and the last seat, so dry-run both ends. Candidates with working solutions have still been rejected here, so tidy boundary code counts as much as the answer.List could just as well be an iterator, has the seats stream in one at a time with no index access and asks for the most guests the row can take. Peeking at seats[i + 1] is gone, so count empty runs in closed form. A run of L empty seats boxed in by occupied seats holds (L - 1) / 2, a run touching one end holds L / 2, and a phantom empty seat past each end folds every case into the first formula. The walkthrough carries the streaming version through.Bulb Switcher: The Perfect-Squares Tell
Problem
n bulbs in a row, numbered 1 to n, and all of them start off. The first round switches every bulb on. Round 2 then toggles every second bulb (2, 4, 6, ...). From there, round i toggles every i-th bulb, so round n touches only bulb n. Return how many bulbs are on after all n rounds.n ranges from 0 to 2^31 - 1, so simulating the rounds will not finish in time.Input encoding. Each test case is a JSON array
[n]. The function returns the count as an integer.Round 1 turns all three on, round 2 turns bulb 2 off, round 3 turns bulb 3 off. Only bulb 1 is left on.
Bulbs 1, 4, 9, 16 and 25 stay on. Every other bulb is toggled an even number of times.
Track one bulb across all rounds. Bulb i is toggled once for each divisor of i, so it ends on exactly when i has an odd number of divisors, which only perfect squares do. Count the squares up to n.
Bulb Switcher: The Perfect-Squares Tell
Click "Run" to execute your code
i flips once per divisor, divisors pair up as d and i / d, and only a perfect square has a divisor paired with itself. Say the brute force out loud, then the square-root idea. A reported version wanted the bulbs themselves (1, 4, 9, 16, 25), so keep a loop that can list them.n = 30 gives [1, 4, 9, 16, 25]. Filtering 1..n for squares costs O(n). Stepping root upward and emitting root * root costs O(sqrt n) and reuses the counting loop line for line. (Worked in the solution.)Valid Parentheses: The Config Validator, in O(1) Space
Problem
Given a string
s of letters, digits and other characters with ( and ) mixed in, return true if every ) closes an earlier unmatched ( and every ( is eventually closed. Every character other than ( and ) is ignored. A string with no parentheses at all is balanced.Input encoding. Each test case is a JSON array
[s]. The function returns a boolean.Skip the digits, the operators and the letter. The inner ( closes after "45+", the outer one closes at the end.
The first two pairs close cleanly, but the ( at index 9 is never closed, so one paren is left open when the string ends.
With a single bracket type, a stack of open parens tells you nothing beyond its height. Track that height as an integer that rises on (, falls on ), never dips below zero and finishes at exactly zero.
Valid Parentheses: The Config Validator, in O(1) Space
Click "Run" to execute your code
"((45+)*a3)", carries digits and operators between the brackets, so everything except ( and ) gets skipped. Most candidates can write the stack, and the reported follow-up asks for O(1) space. With one bracket type, the stack only ever holds copies of (, so its depth is all the information it carries and a single counter replaces it, provided you fail the moment it dips below zero.( and ) count, the stack never holds anything but open parens, so an integer depth can stand in for it. Add one on (, subtract one on ), return false the instant the depth goes negative, and require zero at the end. (Worked in the solution.)Key Takeaways
- ✓Warm-ups on LinkedIn's phone screen are scored like the main problem, so clean code and a hand trace of the edge inputs count as much as the answer.
- ✓Can Place Flowers arrives as theater seating and answers yes or no against a target. Seat greedily at the first legal seat, stop once the count is reached, and dry-run both ends of the row.
- ✓Bulb Switcher reduces to counting perfect squares up to n. Keep a loop that can list them, because a reported version asked for the bulbs themselves.
- ✓Valid Parentheses with one bracket type needs only a depth counter for O(1) space. Fail the moment it goes negative and require zero at the end.
Citing this page?How we research these guides
LinkedIn interview guideKnow what LinkedIn asks before you walk in.
28 coding · 5 system design · 26 behavioral questions
Get their questions first.
InterviewLegend is independent and not affiliated with or endorsed by any company it covers.