How to solve this problem asked in Uber OA :- ↵
↵
You can assume N walls with distinct heights. ↵
↵
You are given an array A. A[i] denotes how many walls can be viewed if you stand after the i'th wall ↵
↵
Example array of walls :- [5 4 2 3 1] ↵
↵
A[1] = 1 ↵
A[2] = 2↵
A[3] = 3 ↵
A[4] = 3 (You can view 5 , 4 , 3 -> if you stand after 3 and observe.) ↵
A[5] = 4 ↵
↵
Given an array A ; find the count of permutations possible of size "N" ("N" walls with distinct heights from 1 to N) ↵
↵
Input :- A : [1 2 3 1 2] ↵
↵
Output :- 4 ↵
↵
[4 3 2 5 1]↵
↵
[4 3 1 5 2]↵
↵
[4 2 1 5 3]↵
↵
[3 2 1 5 4] ↵
↵
Tried many ways couldn't find any that works. ↵
↵
↵
↵
↵
↵
You can assume N walls with distinct heights. ↵
↵
You are given an array A. A[i] denotes how many walls can be viewed if you stand after the i'th wall ↵
↵
Example array of walls :- [5 4 2 3 1] ↵
↵
A[1] = 1 ↵
A[2] = 2↵
A[3] = 3 ↵
A[4] = 3 (You can view 5 , 4 , 3 -> if you stand after 3 and observe.) ↵
A[5] = 4 ↵
↵
Given an array A ; find the count of permutations possible of size "N" ("N" walls with distinct heights from 1 to N) ↵
↵
Input :- A : [1 2 3 1 2] ↵
↵
Output :- 4 ↵
↵
[4 3 2 5 1]↵
↵
[4 3 1 5 2]↵
↵
[4 2 1 5 3]↵
↵
[3 2 1 5 4] ↵
↵
Tried many ways couldn't find any that works. ↵
↵
↵
↵
↵