0%

Symmetric Tree

LeetCode - 0101 Symmetric Tree
https://leetcode.com/problems/symmetric-tree/

Problem Description

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1, 2, 2, 3, 4, 4, 3] is symmetric:

1
2
3
4
5
    1
/ \
2 2
/ \ / \
3 4 4 3

But the following [1, 2, 2, null, 3, null, 3] is not:

1
2
3
4
5
  1
/ \
2 2
\ \
3 3
Read more »

Climbing Stairs

LeetCode - 0070 Climbing Stairs
https://leetcode.com/problems/climbing-stairs/

Problem Description

You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

Note: Given n will be a positive integer.

Example 1:

Input: 2
Output: 2
Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
Read more »

Most Frequent Element in an Array

Problem Description

Given an array, find the most frequent element in it. If there are multiple elements that appear maximum number of times, print any one of them.

Example:

Input: [1, 3, 2, 1, 4, 1]
Output: 1
Explanation: 1 appears three times in an array which is maximum frequency
Input: [10, 20, 10, 20, 30, 20, 20]
Output: 20
Read more »