Minimum Moves to Equalize Array Elements

Introduction Here I will show you how to find out minimum moves to equalize array elements. I will check the equality of elements from two arrays. As a pre-condition both arrays must have equal number of elements, i.e., in other words both arrays must be of same length. I will read each element from both arrays one by one at a time and check how much difference are there between two elements at the same index of both arrays and add to the counter variable to keep track of the…

Continue

Finding Start and End Index of an element in a sorted Array using Kotlin

Finding start and end index of an element in a sorted array using Kotlin programming language will be shown here. The array may contain duplicate elements and we will see how to find a start and end index for an element in this array elements. We may design the algorithm for finding start and end index of an element in a sorted array in various ways but we need to consider also for the optimized solution. We can simply iterate through array elements and find the start and end index…

Continue

Hackerrank Solution: 1D Array – Part 2 using Kotlin

This tutorial will show you Hackerrank 1D Array Part 2 using Kotlin. Let’s play a game on an array! You’re standing at index 0 of an n-element array named game. From some index i (where 0 <= i < n), you can perform one of the following moves: Move Backward: If cell i-1 exists and contains a 0, you can walk back to cell i-1. Move Forward: If cell i+1 contains a zero, you can walk to cell i+1. If cell i+leap contains a zero, you can jump to cell…

Continue

HackerRank Solution: Subarray using Kotlin

This tutorial will show you how to solve HackerRank Subarray using Kotlin. A subarray of an n-element array is an array composed from a contiguous block of the original array’s elements. For example, if array=[1,2,3], then the subarrays are [1], [2], [3], [1,2], [2,3], and [1,2,3]. Something like [1,3] would not be a subarray as it’s not a contiguous subsection of the original array. Please go through first how to create Kotlin project in Eclipse

Continue