Infosys: Top-K salaries per department in SQL without LIMIT
Problem. Given an employee table with salary and department columns, return the employees whose salaries fall in the top K within each department. You can't use LIMIT.
Expected approaches. Per the candidate, the interviewer was looking for a subquery-based answer or a window ranking function (DENSE_RANK or RANK) partitioned by department and ordered by salary descending, then filtered to rank at most K. Because ties matter, the choice of ranking function is a natural follow-up.
Context. This was asked in the technical discussion phase of a Specialist Programmer interview, after a paper-coding phase (sort an array of 0s, 1s and 2s in place, and top-k frequent elements) where the panel expected correct syntax and an optimal solution without a compiler.
What mattered. Being able to explain and dry-run your logic, and to justify time and space complexity. The same discussion went on to Java access modifiers, static versus private, Python generators and the GIL.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.