Yahoo India Web Search

Search results

  1. Dec 14, 2023 · Given an array arr[] consisting of N integers and an integer K, the task is to find the sum of the array elements possible by traversing the array and adding arr[i] / K, K number of times at the end of the array, if arr[i] is divisible by K. Otherwise, stop the traversal.

  2. Find the Duplicate Number - 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.

  3. Find All Duplicates in an Array - Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice.

  4. Learn how to find all the elements occurring more than once in an array of size n with elements from 0 to n-1. See examples, constraints, time and space complexity, and company tags for this easy problem.

    • Using indexOf() and lastIndexOf() Another way to find duplicate elements in an array is by using the indexOf() and lastIndexOf() methods. For each element in the array, check if the first index of the element is equal to the last index of the element, if not, then it is a duplicate element.
    • Using filter() and includes() You can also filter out the duplicate elements from an array using the filter() method. For each element in the array, check if the element is already present in the new array or not, if not, then add it to the new array.
    • Using forEach() and includes() This is the same as using for loop, you need to go through each element in the array and check if the element is already present in the new array or not, if not, then add it to the new array.
    • Using reduce() and includes() The reduce() method executes a function on each element of the array, that results in a single output value of the array.
  5. Jan 21, 2019 · Learn five methods to find duplicate elements in array in java using Brute Force, Sorting, HashSet, HashMap and Java 8 Streams. Compare the time and space complexity of each method and see the code examples.

  6. People also ask

  7. Jul 16, 2024 · Given an array of n elements containing elements from 0 to n-1, with any of these numbers appearing any number of times, find these repeating numbers in O(n) and using only constant memory space. Example: Input: n = 7 , array = {1, 2, 3, 1, 3, 6, 6} Output: 1, 3 and 6. Explanation: Duplicate element in the array are 1 , 3 and 6

  1. People also search for