This combined prompt evaluates string-processing and grouping concepts for anagram detection alongside binary tree traversal and visibility reasoning for the right-side view, assessing algorithmic thinking, data structure usage, and complexity reasoning.
You are given an array of strings words.
Two strings are anagrams if they contain the same characters with the same frequencies (order can differ).
Task: Group the strings into lists where each list contains all strings that are anagrams of each other.
words: string[]
string[][]
(order of groups and order within each group can be arbitrary)
1 <= words.length <= 10^4
, each word length
<= 100
, lowercase English letters.
Example
["eat","tea","tan","ate","nat","bat"]
[["eat","tea","ate"],["tan","nat"],["bat"]]
You are given the root of a binary tree. Imagine looking at the tree from the right side; return the values of the nodes you can see, ordered from top to bottom.
Task: Return an array of the rightmost node’s value at each depth.
root
(binary tree node)
int[]
Example For the tree:
1
has left child
2
and right child
3
2
has right child
5
3
has right child
4
Right-side view is: [1, 3, 4]
Note (interview setting): You may need to define the tree node structure, build a tree from test data, and write basic test cases yourself.