Home Arrays
Category:

Arrays

View algorithms on Arrays

  • Arrays

    [Hackerrank] – Queue using two stacks

    by nikoo28
    10 minutes read

    A queue is a linear data structure which maintains the order in which the elements appear. You need to implement a queue, using two stacks such that it behaves in the same way. If you are unfamiliar with the queue data structure and the stack data structure, it would be a good idea to learn them before approaching this problem. Problem Statement: The basic crux of the problem is that you are to implement a queue and its operations using stacks. It may seem unnecessary in the beginning, as a …

    0 FacebookTwitterLinkedinWhatsappEmail
  • ArraysTheory

    Array Data Structure

    by nikoo28
    8 minutes read

    An array is the most basic data structure one can think of. It may seem very easy to use and in a lot of my posts we have been solving problems using arrays. However, if you are just getting started with programming this post is probably for you. I would like to cover some of the basic concepts that makes this data structure so desirable and easy to use. If you have been programming for a while now this post is probably not written for you. Read along keeping that …

    1 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    [Hackerrank] – Between Two Sets Solution

    by nikoo28
    8 minutes read

    Question: You will be given two arrays of integers and asked to determine all integers between two sets that satisfy the following two conditions:– The elements of the first array are all factors of the integer being considered– The integer being considered is a factor of all elements of the second array Input:a = { 2, 6 }b = { 24, 36 } Output:2 I really want to simplify this really confusing problem statement first. The hardest part about this problem is to understand what is it actually saying. To …

    1 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    [Hackerrank] – Pairs Solution

    by nikoo28
    10 minutes read

    Question: Given an array of integers, find the number of pairs of array elements that have a difference equal to the target value. Example: Input:arr[ ] = {1, 2, 3, 4}k = 1 Output: 3 Problem Statement Let us try to simplify the problem statement first and understand the sample test case. You are given an array of unique integers which is in any random order. Along with the array, you are also given a target value k. If you pick up any 2 integers from the array, they would …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    [Hackerrank] – Missing Numbers Solution

    by nikoo28
    8 minutes read

    Question: You are required to find missing numbers that are left out while an artist transports numbers from one array to other. The output array should be sorted. Input:arr [ ] = {7, 2, 5, 3, 5, 3}brr [ ] = {7, 2, 5, 4, 6, 3, 5, 3} Output:Missing numbers: {4, 6} Problem Statement: Let me try to simplify the problem a little first. The problem description is quite verbose and we narrow down it to quite an extent. To summarize, the artist has an original array brr, and …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    [Hackerrank] – Equal Stacks Solution

    by nikoo28
    10 minutes read

    Question: Given 3 arrays, where each element represent the height of a cylinder. Find the maximum possible height of equal stacks by removing one or more cylinders from the original stack. Example: Input: n1[] = {3, 2, 1, 1, 1}n2[] = {4, 3, 2}n3[] = {1, 1, 4, 1} Output: 5 Problem Statement Let us try to simplify the problem statement first. The problem states that you are provided with 3 sets of arrays. Each element in the array represents the height of a cylinder. Now, all these cylinders are …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    [Hackerrank] – Left Rotation Solution

    by nikoo28
    11 minutes read

    Question: You are given an array of integers. After a left rotation of k times, find the resultant array. Example 1:Input: arr [ ] = {1, 2, 3, 4, 5}, size = 5, k = 2Output: {3, 4, 5, 1, 2} Example 2:Input: arr [ ] = {4, 8, 15, 16, 23, 42}, size = 6, k = 12Output: {4, 8, 15, 16, 23, 42} Terminology: To understand rotation of an array, you can assume that the array is kind of on an infinite conveyor belt, that keeps on looping. …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    Maximum sum contiguous sub-array

    by nikoo28
    9 minutes read

    You are provided with an array of integers. We need to find the sub-array with the maximum sum such that all the elements are contiguous. Example:Input: [-2, -5, 6, -2, -3, 1, 5, -6]Output: 7Explanation: The sub-array with maximum sum is [6, -2, -3, 1, 5] Problem Statement: You are provided with an array of integers. These elements could be all positive, all negative or a combination of both. A sub-array is a smaller array formed using the elements of the original array. The condition for this problem is that …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    Single non-repeating number

    by nikoo28
    7 minutes read

    Let us suppose you are given an array of integers. The special thing about this array is that all numbers are repeated twice except one. Find the single non-repeating number. Example 1:Input: [2, 1, 1]Output: 2 Example 2:Input: [4, 5, 5, 2, 2]Output: 4 Problem statement: You are given an array of all positive integers. All the integers are repeated exactly twice except one. We need to find that number with a linear time complexity and using the minimum space possible. Brute Force Method: When tackling such problems, it is …

    1 FacebookTwitterLinkedinWhatsappEmail

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More