Permutations of Array 2 - Array has duplicates

Problem Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order. Example 1: Input: nums = [1,1,2] Output: [ [1,1,2], [1,2,1], [2,1,1] ] ...

Contains Duplicate 2 - within k distance

Problem Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k. Examples Example 1: Input nums = [1,2,3,1], k = 3 Output: true ...

Contains Duplicate 3 - within k distance and t difference

Problem Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i and j is at most k. OR You are given an integer array nums and two integers indexDiff and valueDiff. Find a pair of indices (i, j) such that: ...

Single Number 2 - All elements except one occur thrice

Problem Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it. You must implement a solution with a linear runtime complexity and use only constant extra space. Examples Example 1: Input : nums = [1, 2, 4, 3, 3, 2, 2, 3, 1, 1] Output : 4 ...

Valid Parentheses Problem

Problem Given a string s 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. Every close bracket has a corresponding open bracket of the same type. Examples Example 1: ...

Find Duplicate Number in array containing n+1 numbers between 1 and n

Problem Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nums, return this repeated number. You must solve the problem without modifying the array nums and uses only constant extra space. OR You are given an array of length n + 1 whose elements belong to the set {1, 2, ..., n}. By the pigeonhole principle, there must be a duplicate. Find it in linear time and space. ...

Majority Element 1

Problem Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Definition Majority Element: If an element appears more than n/2 times in array where n is the size of the array. Examples int [] arrA = {1,3,5,5,5,5,4,1,5}; Output: Element appearing more than n/2 times: 5 int []arrA = {1,2,3,4}; Output: No element appearing more than n/2 times ...

Check if Array is Consecutive Integers

Problem Given a array of unsorted numbers, check if all the numbers in the array are consecutive numbers. Examples Example 1: Input: int [] nums = {21,24,22,26,23,25}; Output: True Explanation: All the integers are consecutive from 21 to 26 Example 2: Input: int [] nums = {11,10,12,14,13}; Output: True Explanation: All the integers are consecutive from 10 to 14 ...

Check if Array is Consecutive Positive Integers

Problem Given a array of unsorted numbers, check if all the numbers in the array are consecutive numbers. This problem is special case for Check if Array is Consecutive Integers. Examples Example 1: Input: int [] nums = {21,24,22,26,23,25}; Output: True Explanation: All the integers are consecutive from 21 to 26 Example 2: ...

Contains Duplicate 1 - Check if array has duplicates

Problem Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. Examples Example 1: Input: nums = [1,2,3,1] Output: true Example 2: Input: nums = [1,2,3,4] Output: false ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy