Count Candidate Pairs Whose Combined Salary Fits the Budget

Last updated: November 29, 2026

Quick Overview

A hiring team can open two roles and has a budget B. Given a list of candidate salary asks, count the unordered pairs of distinct candidates whose combined ask is at most B.

LinkedIn
Coding & Algorithms
Software Engineer
LinkedIn
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


A hiring team can open two roles and has a budget B. Given a list of candidate salary asks, count the unordered pairs of distinct candidates whose combined ask is at most B.

A two-pointer warm-up in the style of LinkedIn's phone screens, set in a Recruiter planning context. The interviewer wants the sort plus two pointers count in O(n log n) and checks the off-by-one in adding `right - left` pairs at once.

What the Interviewer Expects
  • Sorts the asks first
  • Moves two pointers inward based on whether the pair fits
  • Adds right minus left pairs in one step when the smallest fits with the largest
  • Avoids counting a candidate with themselves
  • States O(n log n) time and O(1) extra space after sorting
Key Topics to Cover
two pointers
sorting
counting pairs
budget constraints
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you count pairs with sum in a range [L, B]?
  • What if you can open three roles?
  • How would you return the pair with the largest combined ask still under budget?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list of positive ints asks and an int B. Count index pairs i < j with asks[i] + asks[j] <= B. Equal asks from different candidates are different pairs....

High-Level Design

After sorting, set left = 0 and right = n - 1. If asks[left] + asks[right] <= B, then left pairs with every index from left + 1 through right, because those values are no larger than `asks[rig...


Submit Your Answer
Markdown supported