Posts

Showing posts from June, 2024

Female Coding Pioneer

Ada Lovelace, the first programmer and a visionary mathematician, was chiefly known for her work on Charles Babbage's proposed mechanical general-purpose computer, the Analytical Engine. She was fond of sequences. During her studies she came across an infinite sequence that was generated using the following algorithm, starting with an empty sequence. Starting from step number 1, in step number  i,  the integer  i  is appended to the sequence exactly  k  times where  k  is equal to the number of set bits in  i. Given an array  query  of  n  integers,   for each query, find the value at the given index of the array assuming indexing starts at 0 .  Report an array of  n  integers where the  x th   integer represents the answer to the  x th  query. Example Given, n = 2 and query = [4, 10], the sequence is generated as follows. Step Number Bina...

HackTree

Image
 You are given a tree with n nodes. Each node has a value assigned with it. The cost of a path is defined as the summation of all the values assigned to nodes that belong to the path. The root of the tree is node number 1. Cost of path example The cost of the path 6 -> 5 -> 3 -> 1 in the above tree is 42 + 31 + 20 + 10 = 103. A Vertical Path in a tree is the path that is going up towards the root of the tree. It is not necessary for the path to end at the root. Given a tree with n nodes and an integer k . Find the number of vertical paths such that the (cost of the path) % k = 0 where % represents the modulo operation. Note: The modulo operation returns the remainder of a division after one number is divided by another. For example - 5 % 2 = 1. Example k = 2 tree = There are a total of 8 vertical paths: 1 2 4 2->1 4->1 3 3->4 3->4->1 But only (2 -> 1), (4 -> 1),...