0% found this document useful (0 votes)
45 views2 pages

Hashing Questions

The document discusses three questions - finding the top view of a binary tree, finding two numbers that add up to a target sum in an array, and sorting a string based on character frequency. Sample inputs and outputs are provided for each question.

Uploaded by

sahilsharan2704
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

Hashing Questions

The document discusses three questions - finding the top view of a binary tree, finding two numbers that add up to a target sum in an array, and sorting a string based on character frequency. Sample inputs and outputs are provided for each question.

Uploaded by

sahilsharan2704
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

HASHING QUESTIONS

[email protected]
Question 1 :
Bottom View of a Binary Tree
The top view of a binary tree is the set of nodes visible when the tree is viewed from the top.
Given a binary tree, print the top view of it. The output nodes can be printed in any order.

Sample Input :

e e
20

er
/ \

h
8 22

e
/ \ \

m
5 3 25

g
/ \

s
10 14

m
Sample Output : 5 10 3 14 25

id @
Hint : Use the concept of Vertical Order

Te l e
Question 2 :
Two Sum
Given an array of integers arr[ ]and an integer target, return indices of the two numbers such
that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the
same element twice.
You can return the answer in any order.

Sample Input 1 : arr = [2, 7, 11, 15], target = 9


Sample Output 1 : [0, 1]
As arr[0] + arr[1] == 9, we return [0, 1].

Sample Input 2 : arr = [3,2,4], target = 6


Sample Output 2 : [1, 2]

Question 3 :
Sort by Frequency
Given a string s, sort it in decreasing order based on the frequency of the characters. The
frequency of a character is the number of times it appears in the string.
Return the sorted string. If there are multiple answers, return any of them.

[email protected]
Sample Input 1 : s = "cccaaa"
Sample Output 1 : "aaaccc"
Both 'c' and 'a' appear three times, so both "cccaaa" and "aaaccc" are valid answers.
Note that "cacaca" is incorrect, as the same characters must be together.

Sample Input 2 : s = "tree"

e e
Sample Output 2 :"eert"

er
'e' appears twice while 'r' and 't' both appear once.

h
So 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer.

m e
sg
BONUS (LRU Cache) IMPORTANT

m
Please go on the platform and solve this question : https://leetcode.com/problems/lru-cache/

id @
Te l e

You might also like