# Archive for January 2017

Problem statement Given a sorted integer array without duplicates, return the summary of its ranges for consecutive numbers. For example, given , return . Solution public class SummaryRanges { private static String summary(int[] a) { String ans = “”; int start = a[0]; ans = ans + start; for (int . . . Read more

Problem statement Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the order of . If the target is not found in the array, return . For example, given and target value 8, return . . . . Read more

Given a string and a string , find the minimum window in which will contain all the characters in in complexity . Sample Input 0 S = “ADOBECODEBANC” T = “ABC” Sample Output 0 BANC Solution The first step we are going to take is, count the occurrences of each . . . Read more

Problem statement You have a string, , of lowercase English alphabetic letters. You can perform two types of operations on : Append a lowercase English alphabetic letter to the end of the string. Delete the last character in the string. Performing this operation on an empty string results in an . . . Read more

Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers. Input Format A single line of five space-separated integers. Constraints Each . . . Read more

There are two kangaroos on an x-axis ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location and moves at a rate of meters per jump. The second kangaroo starts at location and moves at a rate of meters per jump. Given the . . . Read more

The Knuth shuffle algorithm is an algorithm for randomly shuffling the elements of an array arr of size given a function that generates a uniformly distributed random number in time. The algorithm produces an unbiased permutation. That is, every permutation is equally likely. for i in range(n-1,0,-1): j = integer . . . Read more

Problem statement We call an quadruple of positive integers, , beautiful if the following condition is true: Note: is the bitwise XOR operator. Given and , count the number of beautiful quadruples of the form where the following constraints hold: When you count the number of beautiful quadruples, you should . . . Read more

Problem statement Given a set of hotels and its guests reviews, sort the hotels based on a list of words specified by a user. The criteria to sort the hotels should be how many times the words specified by the user is mentioned in the hotel reviews. Input The first . . . Read more

Problem statement Given a list of numbers, e.g.: 25626 25757 24367 24267 16 100 2 7277 Output a delta encoding for the sequence. In a delta encoding, the first element is reproduced as is. Each subsequent element is represented as the numeric difference from the element before it. E.g. for . . . Read more