Trilogy Coding Questions
Trilogy Coding Questions
The teacher in Bitland writes the numbers from 1 to A (inclusive) on Blackboard. Now, he gives
the following task-
- Choose some numbers(possibly all or none) from the blackboard.
- Bitwise Xor of the chosen numbers shoul be 0 (if you pick no elements, Bitwise Xor is
0).
- The count of chosen numbers should be maximum.
- If there are multiple possible options which yield maximum count. Choose the one with
minimum sum.
- If there are still multiple possible options. Choose the one which is lexicographically
smallest.
Formally, you are provided with an integer A. Return an integer array denoting a sequence of
numbers satisfying the above conditions in sorted order (if you pick no elements, return an
empty array).
Problem Constraints
1<=A<=105
Example
Input 1:
A=3
Output 1:
[1,2,3]
Input 2:
A=2
Output 2:
[]
Tired Librarian
You are a librarian, and after a long day, you decide to collect all the books kept on tables.
In front of you, there are several stacks of books. A[i] denotes the size of the i’th stack of
books.In one move you can pick an existing stack and merge it with another stack of books.
The efforts required for this task is the size of stack being added. After this move new stack size
stacks.
To make this task fun you like to add some challenge to it and decide that, to any stack you will
not add books to it for more than B times added to any other stack.
What is the minimum efforts required to collect all the books in one stack?
Problem Constraints
Example
Input 1:
A = [3,2,1,10]
B=2
Output 1:
7
Input 2:
A = [3,3,2]
B=1
Output 2:
7