Tag Archives: Array

Array stable partition

Given an array of positive and negative integers, re-arrange it so that you have positives on one end and negatives on the other. BUT retain the original order of appearance. do it in-place  e.g. 1, 7, -5, 9, -12, 15 … Continue reading

Posted in Uncategorized | Tagged | 1 Comment

Sort an integer array in a special way

Problem:Given an integer array, sort the integer array such that the concatenated integer of the result array is max. Example: [4, 94, 9, 14, 1] will be sorted to [9,94,4,14,1] where the result integer is 9944141 Solution: This is an … Continue reading

Posted in Uncategorized | Tagged | Leave a comment

The smallest triangle problem

Problem: Given 3 unsorted integer array, find out the minimum triangle between the three arrays. That is, find out arr1[i], arr2[j] and arr3[k] such that dist = |arr1[i]-arr2[j]| + |arr2[j]-arr3[k]| + |arr1[i]-arr3[k]| is a minimum. Solution: Let us use the … Continue reading

Posted in Uncategorized | Tagged | Leave a comment

Print the products of 2 and 5 in increasing order

Problem: Print the numbers of the form 2^i*5^j in increasing order. Example: 1, 2, 4, 5, 8, 10, 16, 20,….. How to do it efficiently? The most intuitive way is to create a very long bitmap, and then maintain two … Continue reading

Posted in Uncategorized | Tagged , | 2 Comments

Find out the smallest positive integer that is not in the given array

Problem:  Given is an unsorted integer array, find out the smallest positive integer that is not in this array. Example: {1,3,4, 6}  => 2.   {0,2,5,4}  => 1. {1,2,3} =>4.  {-2,5,2,1} =>3 Becareful: The array may contain negative integer, and 0 … Continue reading

Posted in Uncategorized | Tagged | 1 Comment