Binary Tree Right Side View
Function Name: rightSideView
Description
Write a function that takes the root node of a binary tree and returns the value of the nodes visible when the tree is viewed from the right side. This is done by returning the rightmost node at each level of the tree. If no rightmost node is present at any level (such as in a left-leaning tree), the function should return the last node in that level's traversal.
Requirements
- The function must take exactly one parameter: the root node of the binary tree.
- The binary tree nodes will have properties 'value' (int), 'left' (BinaryTreeNode or null), and 'right' (BinaryTreeNode or null).
- The function should return an array of integers representing the values seen when looking at the tree from the right side.
- If the input tree is empty, the function should return an empty array.
- The nodes at each level should be considered from left to right when determining which is last.
Examples
Given the following binary tree: 1 / \ 2 3 \ \ 5 4Calling rightSideView(root) should return [1, 3, 4].Similarly, for a left-leaning tree like: 1 / 2 /3Calling rightSideView(root) should return [1, 2, 3].
Links
Run-Length Encoding
Thu Nov 07 2024
Implement a function to perform run-length encoding on a string.Run-length encoding is a basic form of data compression, where sequences of the same data value (in this case, characters) are stored as a single data value and a count.This function should take a string as input and return the encoded string.The output string should be formed by concatenating each unique character with the number of times it appears consecutively in the input string.The function should be case-sensitive ('A' is considered different from 'a').If a character occurs only once consecutively, it should be followed by the number '1'.The function must handle empty strings gracefully by returning an empty string.
Aggregate Event Times
Sat Nov 09 2024
Write a function that takes a list of time intervals for various events, where each interval is represented as a pair of strings (start, end) in 24-hour 'HH:MM' format. The function should return a list of merged intervals if any two intervals overlap.The input list can be unsorted and there might be multiple intervals overlapping. The merged intervals should be outputted in sorted order, without any overlapping.Assume that time intervals are closed, meaning '10:00' - '12:00' and '12:00' - '13:00' do overlap at '12:00'.