Archive for the ‘Amazon’ Category.
November 12, 2009, 8:25 pm
Find the maximum rectangle completely contained inside a histogram where each bars has a width of 1 unit. The heights of the bars of the histograms are given in an array e.g. {4,2,10,8,12,13,15,8,6} and they have a fixed width w = 1, say. The rectangles formed here are: 4X1, 2X9, 10X1, 8X6, 12X3, 13X2, 15X1, 8X6, 6X7 Thus, max-area rectangle = 8X6 = 48
November 12, 2009, 10:14 am
Find the longest palindrome in a given string
November 10, 2009, 9:41 am
Given a array of 0’s,1’s and 2’s. Sort the array.
November 10, 2009, 8:10 am
Find Median of 2 sorted arrays
November 8, 2009, 6:55 am
Given a Binary Search Tree, write a program to print the kth smallest element
November 6, 2009, 11:50 pm
This is a very common interview questions and comes in various forms. The most common one is of the following format
Problem 1
Given an array of 999 distinct integers ranging from 1 to 1000 including. Find which number is missing. Restrictions: loop over the array only once, can’t allocate an additional array.
Another version of the problem is where 2 numbers are missing.
Problem 2
Given an array of 998 distinct integers ranging from 1 to 1000 including. Find which 2 numbers are missing.
Restrictions: loop over the array only once, can’t allocate an additional array.
November 4, 2009, 10:56 am
A log file is of the following format
sessionid ipaddress
1234 127.0.0.1
4567 127.0.0.1
Find the list of top 10 IP Addresses that have the most log entries.
November 4, 2009, 8:46 am
Implement a hash table with efficient implementation for listing the elements.
November 3, 2009, 12:09 pm
Write an algorithm to shuffle an array of 52 integers so that each number has equal probability to be in any of the 52 positions.
October 29, 2009, 11:50 am
searchJars.sh :
-----------------------------------------------------
#!/bin/bash
while getopts "n:il" optionName; do
case "$optionName" in
i) case_sensitive_op=-i;;
l) long_format=Y;;
n) search_expr="$OPTARG";;
[?]) echo "Usage: searchJars [-i] [-l] -n ";exit 1;;
esac
done
if [ -z $search_expr ]
then
echo "Usage: searchJars [-i] [-l] -n ";
exit 1;
fi
if [ $# -lt 1 ]
then
echo "Usage: searchJars [-i] [-l] -n ";
exit 1;
fi
REG_EXPR="$search_expr"
for i in `find . -name "*jar"`
do
jar tvf $i 2> /dev/null | grep $case_sensitive_op $REG_EXPR > /dev/null
if [ $? == 0 ]
then
echo $i
if [ "$long_format" = "Y" ]
then
jar tvf $i | grep $case_sensitive_op $REG_EXPR | awk '{ print " "$8}'
echo "-----------------------------------------------------"
fi
fi
done
-----------------------------------------------------
Usage:
Usage: searchJars [-i] [-l] -n CLASS_NAME_OR_EXPRESSION