1. Consider a binary tree of N vertices such that children of node k are 2*k and 2*k+1. Vertex 1 is the root of the tree and each node has an integer value associated with it.
Such a tree may be represented as an array of N integers by writing down values from consecutive nodes.
The tree can be represented as an array [-1, 7, 0, 7, -8].
A node is said to be at level x if the length of the shortest path between that node and root x-1. So, the root is at level 1, the children of root are at level 2, and so on.
Your task is to find the smallest level number x such that sum of all nodes at level x is maximal.
Examples: Given array A such that: A=-1, A=7, A=0, A=7, A=-8. The function should return 2.
Input : [-1, 7, 0, 7, -8] Output : 2
2. Imagine you have a special keyboard with all keys in a single row. The layout of characters on a keyboard is denoted by a string S1 of length 26. S1 is indexed from 0 to 25. Initially, your finger is at index 0. To type a character, you have to move your finger to the index of the desired character. The time taken to move your finger from index i to index j is |j-i|, where || denotes absolute value.
Write a function solution(), that given a string S1 that describes the keyboard layout and a string S2, returns an integer denoting the time taken to type string S2.
S1 = abcdefghijklmnopqrstuvwxyz
S2 = cba
Input : S1 = abcdefghijklmnopqrstuvwxyz, S2 = cba Output : 4
- Google Interview Experience | Set 7 (For Software Engineering Intern)
- Microsoft Interview Experience 2019 | Off-Campus Software Engineering Internship
- Microsoft Interview Experience 2019 | Off-Campus Software Engineering Internship (Hyderabad)
- Microsoft Interview SDE intern 2019
- Philips Intern Interview Experience 2019
- Samsung R&D Banglore On-Campus Intern July-2019
- Interview at Travel d'globe made me fall in love with startup
- Dunzo Interview for Software Developer Intern
- JP Morgan Chase and Co. Interview Experience | Software Developer Intern
- Samsung Semiconductor Institute of Research(SSIR Software) Intern/FTE | Set-2
- Samsung Semiconductor Institute of Research (SSIR software) intern/FTE | Set-1
- Interview Experience at Expedia India for the profile of a Software Intern
- Google Summer Trainee Engineering Program(STEP) Interview Experience
- Traveloka Interview Experience (software engineer intern + full time)
- Samsung Semiconductor Institute of Research(SSIR Software) Intern On Campus
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.