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. ...

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: ...

Find element which appears maximum number of times in the ranged array

Problem Given an array of integers occurring between range[0, n) where n is length of the array, write a algorithm to find the element which appears maximum number of times in the array. Examples Example 1: int [] nums = {4, 1, 5, 2, 1, 5, 9, 8, 6, 5, 3, 2, 4, 7}; n = 14 Output: Element repeating maximum no of times: 5, maximum count: 3 ...

Find duplicate number in array with 1 to N+1 numbers with one number repeating

Problem Suppose you have an array of 1001 integers. The integers are in random order, but you know each of the integers is between 1 and 1000 (inclusive). In addition, each number appears only once in the array, except for one number, which occurs twice. Assume that you can access each element of the array only once. Describe an algorithm to find the repeated number. If you used auxiliary storage in your algorithm, can you find an algorithm that does not require it? ...

Find All Numbers Disappeared in an Array Problem

Problem Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums. Examples Example 1: Input: nums = [4,3,2,7,8,2,3,1] Output: [5,6] Example 2: Input: nums = [1,1] Output: [2] ...

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