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”

Design a site like this with WordPress.com
Get started