Climbing Stairs- LeetCode

Problem Statement 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 toContinue reading “Climbing Stairs- LeetCode”

Palindrome Number- LeetCode

Problem Statement Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: true Example 2: Input: -121 Output: false Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome. Example 3: Input: 10Continue reading “Palindrome Number- LeetCode”

Valid Parentheses- LeetCode

Problem Statement Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid. Example 1: Input: “()” Output:Continue reading “Valid Parentheses- LeetCode”

Longest Common Prefix-Leetcode

Problem Statement Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string “”. Example 1: Input: [“flower”,”flow”,”flight”] Output: “fl” Example 2: Input: [“dog”,”racecar”,”car”] Output: “” Explanation: There is no common prefix among the input strings. Intuition Complexity Analysis Time complexity : O(S) ,Continue reading “Longest Common Prefix-Leetcode”

Remove Duplicates from Sorted Array- LeetCode

Problem Statement Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Example 1: Given nums = [1,1,2], Your function should return length = 2, with the first two elementsContinue reading “Remove Duplicates from Sorted Array- LeetCode”

Remove Element- LeetCode

Problem Statement Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.The order of elements can be changed. It doesn’t matter what you leave beyond the new length. Example 1: GivenContinue reading “Remove Element- LeetCode”

Binary Tree Reverse Level Order Traversal- LeetCode

Problem Statement Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (i.e, from left to right, level by level from leaf to root). For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its bottom-up level order traversal as: [ [15,7], [9,20], [3] ] Intuition Alternative Explanation BinaryContinue reading “Binary Tree Reverse Level Order Traversal- LeetCode”

Two Sum Problem- LeetCode

Problem Statement Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example:- Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7Continue reading “Two Sum Problem- LeetCode”

Design a site like this with WordPress.com
Get started