CodeNation Intern Hiring 2021 Program Questions

Revision en1, by priyanshu-panwar, 2020-07-28 07:51:10

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 : - 1iy-Update a[i] = y - 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 fis 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.

Please try to solve them.

Tags codenation, internship

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English priyanshu-panwar 2020-07-28 08:20:05 1020 Added Question - 3
en3 English priyanshu-panwar 2020-07-28 07:55:07 2 Tiny change: 'e sum of fis in the s' -> 'e sum of f[i]s in the s'
en2 English priyanshu-panwar 2020-07-28 07:53:06 23
en1 English priyanshu-panwar 2020-07-28 07:51:10 2901 Initial revision (published)