Had an Adobe coding round today on HackerRank. 90 mins - 3 questions.

Q1. You are given an integer N and a priority array for the 26 letters of the english alphabet. Generate a string of N length using lowercase letters, such that the following function is maximised.

```
f(str) = summation [ i * priority[str[i]] ] for i = 0..(len(str)-1)
```

If multiple such strings are possible, output the one lexicographically least.

Some sample cases:

```
Input:
1 # N
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 # priority of alphabets
Output:
a
Input:
2
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1
Output:
ae
```

Q2: Given an array of integers (length of array is of the order `10**5`

.) We need to find out if they are / can be made in ascending sorted order. However we can do only one operation of the forms:

- Swap the numbers at two indices

OR - Reverse a contiguous segment of the array

Given the array,

- if the numbers are already in sorted form, print "yes" in a line and do no more
- If they can converted to sorted form with just one operation, print "yes" in a line
- if we are swapping, then print "swap l r" in a seperate line where the "l" and "r" are the two indexes to be swapped
- if we are reversing a segment, then print "reverse l r" on a seperate line where "l" and "r" are the two bounding indexes of the reversed segment

- if no such conversion is possible, print "no" in a line and do no more

Swapping is preferred over reversing a segment.

Some sample cases:

```
Input:
3 # the length of array
3 1 2 # the array
Output:
no
Input:
2
4 2
Output:
yes
swap 1 2 # 1 - based indices
Input:
5
1 2 3 4 5
Output:
yes
Input:
6
1 5 4 3 2 6
Output:
yes
reverse 2 5
```

Q3: We have a cubic room of N edge length filled with unit cube sized light bulbs. Initially, some of them are ON and others are OFF. At the passing of unit time, a lightbulb can go from OFF state to ON if it's adjacent bulb is ON. Print the total time it will take for all the bulbs to become ON. If it is impossible, print -1.

The adjacent neighbours of a lightbulb at coordinates `(X, Y, Z)`

are at coordinates `(X+1, Y, Z)`

, `(X-1, Y, Z)`

, `(X, Y+1, Z)`

, `(X, Y-1, Z)`

, `(X, Y, Z-1)`

and `(X, Y, Z+1)`

.

Input format is two integers N, M where N is edge length of room and M is the number of bulbs already ON. The next M lines have three space separated integers representing the coordinates `(X, Y, Z)`

.

```
Sample Input:
5 3
1 1 1
3 3 3
2 2 2
```