Jewels and Stones

Question You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels. The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so “a” is considered a different type of stone from “A”. [Read More]

Java program to push zeroes to the end of the array

Problem Given an array of random numbers, push all the zeroes of a given array to the end of the array. Solution We will iterate through the array and move all non zero elements to the front first. We will then fill the remaining array elements with zeroes until we reach the end of the array. Complexity: O(n) package com.interview.prep.programs; public class MoveZeroesToTheEndOfTheArray { public int[] moveZeroes(int[] numbers) throws Exception { if (numbers ! [Read More]