Yesterday, there was a CodeNation Intern Hiring Test that got failed due to Hackerrank server down problem. But the questions are available, I snapped them in the mean time. If someone can please solve them:
QUESTION — 1 Beautiful Tree You are given a tree, rooted at 1, with N vertices (indexed from 1 to N). Each vertex has a value associated with it. The value of ith vertex is a[i]. Consider f[i] as the a[i]th beautiful number. A beautiful number is a positive number, whose sum of the square of its digits is less than or equal to X. You have to process M queries, where each query can be : Query 1- 1iy-Update a[i] = y. Query 2- 2i — Output the sum of for all the nodes in the sub-tree of node i (including node i), since the output can be very large, answer it modulo 998244353
Input/Output Format Input The first line contains N, M, and X, where N is the number of vertices, and M is the number of queries and X is the upper limit to check for a beautiful number. Each of the next N — 1 lines contains Pair of vertices representing a tree edge. i.e. Nth line having (u, v) implies u; is connected to v and vice-versa. Next Line contains N numbers denoting a[i] the value associated with ith node. Each of the next M lines will represent the query as explained above. Output For each query of type 2 answer, the sum of f[i]s in the sub-tree of node i (including node i) modulo 998244353.
Sample Case Input : 3 3 5 1 2 1 3 1 2 3 2 1 1 2 5 21 Sample Output 13 23
Explanation For X=5. Initial few f[i]'s are [1, 2, 10, 11, 12]
This problem went over my head. Didn't even understand it.
Question — 2: Laser Tag! CodeNation Fresher batch has a tradition of laser tag tournaments. In laser tag, two teams play against each other. A team can have any number of players >= 1. The two teams can have unequal team members. For successful completion of this tournament, Ipshita [our HR] wants that every person must have played against every other person, as part of different teams. Every Laser tag match takes 30 minutes to complete. Now the gaming arena has allowed Codenation to play for a maximum of X hours after which the arena closed. Given the number of folks in the batch as N, you will have to find out if Codenation will be able to finish the tournament before the complex closes? Note: Please return output as 0 or 1, 1 means tournament will successfully complete, 0 otherwise Note: Partial Points are present
Input Format The input contains 2 integers N and X, where N is the number of folks in the batch, and X is the number of hours they are allowed to play.
Input 2 1 Sample Output 1 Explanation For 2 players only 1 laser tag match is enough so 30 minutes (<= 1 hour) is enough for the tournament to end.
Question -3 ZAURXOR
You are given an array of integers A of size N. You perform a certain operation K times on the array A, modifying the array with every operation. The operation is to replace the array A with a new array, which is the XOR of the adjacent elements of A, and of length size(A)-1. You are given an index M, the value of this index in array A after K operations is to be found. Note: Partial points are present
Sample Case Input 4 (N) 2 (K) 1 (M) 1 2 3 4 (Array) Sample Output 6 Explanation Original Array => 1234 Operation 1 => 3 1 7 (1 XOR 2 = 3, 2 XOR 3 =1, 3 XOR 4 = 7) Operation 2 => 2 6 (3 XOR 1 = 2, 1 XOR 7 = 6) M is 1, so after 2 operations, A[1] = 6
For better visualisation of questions, I have posted article on LeetCode with better indentation, you can see the questions there: https://leetcode.com/discuss/interview-question/759851/CodeNation-Intern-Hiring-2021-Program-Questions
Please try to solve them and answer in the comment with the algo or something. THANK YOU