Solve odd-string, digit swap, patient slot assignment
DRWSoftware Engineer · Online AssessmentLast updated
This multi-part problem evaluates string manipulation and parity/combinatorics for constructing odd-occurrence strings, greedy optimization and minimal-change reasoning for digit-swap distance minimization, and bipartite matching/assignment skills for patient slot allocation.
Question
Task 1 – Odd-occurrence string: Write a function that, given an integer N (1..200 000), returns a length-N lowercase string in which every letter that appears occurs an odd number of times.
Task 2 – Min-swap closest numbers: Write a function solution(string S, string T) that, given two digit strings S and T of equal length N (1..100 000) with no leading zeros, returns the minimum number of position-wise digit swaps needed to minimize |int(S) – int(T)|.
Task 3 – Patient slot assignment: Write a function solution(int[] A, int[] B, int S) that, given two arrays A and B of length N (1..100 000) containing preferred doctor-appointment slots (1..S, where S ≤ 100 000) for each patient, returns true if all patients can be assigned one of their two preferred slots with no slot shared by more than one patient, otherwise false.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.