The Prom
Learn this problemProblem statement
N people stand in a line with IDs from 1 to N to enter their high school's prom.
Given a string S, where '0' indicates girls and '1' indicates a boy. When a boy arrives, he pairs up with the girl standing immediately ahead him in line. They then leave the line to go to the dance floor.
To ensure that everyone at the prom gets one dance, each boy finds the ID of the girl who he danced with. If a boy cannot go on a date, the answer is -1.
Function
solve(N: int, S: String) → int[]
Complete the function solve. This function takes the following 2 parameters:
N: Represents the number of peopleS: Represents the binary string denoting the genders
Input format for custom testing
Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code.
Return Value
Return an integer array containing, for each boy in arrival order, the ID of the girl he dances with or -1 when no girl is available.
Note:
Your code is run against multiple hidden test cases, so the returned array must satisfy the contract for every valid input.
Limits
- Time Limit: 1.0 sec(s) for each input file
- Memory Limit: 256 MB
- Source Limit: 1024 KB
Scoring
Score is assigned if any testcase passes
Examples
Example 1
N = 3S = "011"return = [1, -1]Example 2
N = 11S = "10001111110"return = [-1, 4, 3, 2, -1, -1, -1]Example 3
N = 7S = "0000100"return = [4]Constraints
- 1 ≤ N ≤ 10^5
- S[i] ∈ {0, 1} ∀ i ∈ [1,N]