robb.krakow
BAN USER- 1of 1 vote
AnswersGiven an integer 'n', create an array such that each value is repeated twice. For example
- robb.krakow in United States
n = 3 --> [1,1,2,2,3,3]
n = 4 --> [1,1,2,2,3,3,4,4]
After creating it, find a permutation such that each number is spaced in such a way, they are at a "their value" distance from the second occurrence of the same number.
For example: n = 3 --> This is the array - [1,1,2,2,3,3]
Your output should be [3,1,2,1,3,2]
The second 3 is 3 digits away from the first 3.
The second 2 is 2 digits away from the first 2.
The second 1 is 1 digit away from the first 1.
Return any 1 permutation if it exists. Empty array if no permutation exists.
Follow up: Return all possible permutations.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Data Structures - 2of 2 votes
AnswersQuestion : Given a set of N numbers [1,N], partition them into 2 disjoint subsets based on a set of K queries.
- robb.krakow in United States
Each query is of the type (n1, n2) where n1 and n2 are distinct numbers from the set and n1 and n2
belong to opposite subsets.
Example:
Input:
Input:
N = 4
K = [(1, 2), (1, 3), (2, 4)]
Output:
Set 1 : (1,4)
Set 2 : (2,3)| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Data Structures
Would you mind explaining the code and your thought process just so I can understand it better?
- robb.krakow July 27, 2018
what's the time complexity of this solution?
- robb.krakow May 09, 2019