Concatenation of Array LeetCode Solution

Problem Statement : Concatenation of Array LeetCode Solution – Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed). Specifically, ans is the concatenation of two nums arrays. Return the array ans. Example : Example 1 Input: nums = [1,2,1] Output: [1,2,1,1,2,1] Explanation: The array …

Read more

Fibonacci Number LeetCode Solution

Problem Statement Fibonacci Number LeetCode Solution – “Fibonacci Number” states that The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, F(0) = 0, F(1) = 1 F(n) = F(n – 1) + F(n …

Read more

Longest Common Prefix Leetcode Solution

Problem Statement The Longest Common Prefix LeetCode Solution – “Longest Common Prefix” states that given an array of strings. We need to find the longest common prefix among these strings. If there doesn’t exist any prefix, return an empty string. Example: Input: strs = [“flower”,”flow”,”flight”] Output: “fl” Explanation: “fl” is the longest …

Read more

Maximum Difference Between Increasing Elements LeetCode Solution

Problem Statement Maximum Difference Between Increasing Elements LeetCode Solution – Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] – nums[i]), such that 0 <= i < j < n and nums[i] < nums[j]. Return the maximum difference. If no such i and j exists, return -1. Examples & Explanations Example 1: Input: nums = [7,1,5,4] Output: 4 Explanation: The maximum difference occurs …

Read more

Valid Palindrome II Leetcode Solution

Problem Statement The Valid Palindrome II LeetCode Solution – “Valid Palindrome II” states that given the string s, we need to return true if s can be a palindrome string after deleting at most one character. Example: Input: s = “aba” Output: true Explanation: The input string is already palindrome, so there’s …

Read more

Reverse Words in a String III LeetCode Solution

Problem Statement Reverse Words in a String III LeetCode Solution – We are given a string and are asked to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Examples & Explanations Example 1: Input: s = "Let's take LeetCode …

Read more

Remove Duplicates from Sorted List LeetCode Solution

Problem Statement Remove Duplicates from Sorted List LeetCode Solution – We are given the head of a sorted linked list. We are asked to delete all the duplicates such that each element appears only once and return the linked list sorted as well. Examples & Explanations Example 1: Input: head …

Read more

Valid Parentheses Leetcode Solution

Problem Statement The Valid Parentheses LeetCode Solution – “Valid Parentheses” states that you’re given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’. We need to determine whether the input string is a valid string or not. A string is said to be a valid string if open brackets must be closed …

Read more

Can Place Flowers LeetCode Solution

Problem Statement Can Place Flowers LeetCode Solution – You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots. Given an integer array flowerbed containing 0‘s and 1‘s, where 0 means empty and 1 means not empty, and an integer n, return if n new flowers can be planted in …

Read more

Translate »