@@ -0,0 +1,2649 @@
+package interviewquestions.java;%0A%0A/**%0A * You have a list of several million words unsorted.%0A * Find the largest and the smallest words that can be typed by a single hand%0A * on a qwerty-style keyboard.%0A * Following the rules of finger placement, a word can either be typed fully on%0A * the left-hand side of the keyboard, the right-hand side, or both.%0A * Find the largest and smallest left-hand word(s),%0A * and the largest and smallest right-hand word(s).%0A *%0A * You are given:%0A *   - millions of words, unsorted%0A *   - set of left-hand chars: a,s,d,f, ...%0A *   - set of right-hand chars: j,k,l, ...%0A */%0Apublic class LeftRightHandWords %7B%0A  public static class Result %7B%0A    public String largestLeft;%0A    public String largestRight;%0A    public String smallestLeft;%0A    public String smallestRight;%0A  %7D%0A%0A  public static Result search(String left, String right, String%5B%5D words) %7B%0A    Result res = new Result();%0A%0A    long smLeft = Long.MAX_VALUE, smRight = Long.MAX_VALUE;%0A    long lgLeft = Long.MIN_VALUE, lgRight = Long.MIN_VALUE;%0A%0A    for (String word : words) %7B%0A      if (valid(left, word)) %7B%0A        if (word.length() %3C smLeft) %7B%0A          smLeft = word.length();%0A          res.smallestLeft = word;%0A        %7D else if (word.length() %3E lgLeft) %7B%0A          lgLeft = word.length();%0A          res.largestLeft= word;%0A        %7D%0A      %7D else if (valid(right, word)) %7B%0A        if (word.length() %3C smRight) %7B%0A          smRight = word.length();%0A          res.smallestRight = word;%0A        %7D else if (word.length() %3E lgRight) %7B%0A          lgRight = word.length();%0A          res.largestRight= word;%0A        %7D%0A      %7D%0A    %7D%0A%0A    return res;%0A  %7D%0A%0A  public static boolean valid(String side, String word) %7B%0A    for (Character ch : word.toCharArray()) %7B%0A      if (side.indexOf(ch) %3C 0) return false;%0A    %7D%0A    return true;%0A  %7D%0A%0A  public static void main(String%5B%5D args) %7B%0A    final String left = %22qwerasdfzxcvtgb%22;%0A    final String right = %22uiopjklmnhy%22;%0A%0A    Result res;%0A%0A    res = search(left, right, new String%5B%5D %7B%0A        %22qwert%22,%0A        %22rararararararara%22,%0A        %22asd%22,%0A        %22asdlkj%22,%0A        %22iosakbrknerlk%22,%0A        %22mmmmmm%22,%0A        %22llllllllllllllllllll%22,%0A        %22laskdj%22,%0A        %22llll%22,%0A        %22qqqqqqqqqqqqqqqqqqqq%22,%0A        %22p%22,%0A    %7D);%0A%0A    test(res.smallestLeft.equals(%22asd%22));%0A    test(res.smallestRight.equals(%22p%22));%0A    test(res.largestLeft.equals(%22qqqqqqqqqqqqqqqqqqqq%22));%0A    test(res.largestRight.equals(%22llllllllllllllllllll%22));%0A  %7D%0A%0A  public static void test(boolean condition) %7B%0A    // assertions are disabled by default in java, mimic their behaviour here%0A    if (!condition) %7B%0A      throw new AssertionError(%22invalid test%22);%0A    %7D%0A  %7D%0A%7D%0A

find the longest/shortest word that can be written using left/right hand only