diff --git a/bin/Topcoder.class b/bin/Topcoder.class index a98fd3b..5fd1cf5 100644 Binary files a/bin/Topcoder.class and b/bin/Topcoder.class differ diff --git a/src/Topcoder.java b/src/Topcoder.java index e8c5a4e..fba4f4c 100644 --- a/src/Topcoder.java +++ b/src/Topcoder.java @@ -1,3 +1,6 @@ +import java.util.Arrays; +import java.util.HashSet; + public class Topcoder { @@ -6,7 +9,13 @@ public static void main(String[] s) { Topcoder tc = new Topcoder(); //System.out.println("Will all but 1st params add to 1st param-"+tc.buy(10,2,41,2,2)); - tc.checkCharMatch(); + //tc.checkCharMatch(); + //System.out.println(tc.minDucks(new int[]{9,3,6,4})); + //System.out.println(tc.getMinimum("o??x",9,4)); + //System.out.println(tc.train(new int[]{5,5})); + //System.out.println(Arrays.toString(tc.find(100000,new int[]{100000}))); + System.out.println(tc.maxTurns(new int[] {55, 52, 61, 204, 207, 54, 60, 202, 57, 58, 53, 210, 51, 59, 209, 205, 208, 201, 206, 211, 203, 56})); + } // recursion @@ -20,7 +29,7 @@ public String buy(int price, int b1, int b2, int b3, int b4) int sum=0; for(int j=0;j<4;j++) { - if((i & (1<max) + max = a; } + + return (max - (min-1)) - ducks.length; //http://community.topcoder.com/stat?c=problem_statement&pm=11631 } - int swapToPossibleMax(int n) + // Sorted Array Create from unsorted array by moving one value at a time - Find : Number of moves required on optimal solution for Worst case + int solve(int[] T) { - char[] c = Integer.toString(n).toCharArray(); - int m_idx = -1; - char max=0; - - if(c.length==1) - return -1; + int moves = 0; + for(int i=0;i<(T.length/2);i++) // note: half the array comparison is enough + { + moves += T[T.length-i-1] - T[i]; + } + return moves; // http://community.topcoder.com/stat?c=problem_statement&pm=11336 + } + + // Fill '?' in string with 'o' or 'x' to make palindrome with minCost + int getMinimum(String s, int oCost, int xCost) + { + char[] cArr = s.toCharArray(); + int cost = 0; + int l = cArr.length; - //choosing the max elem other than first one - for(int i=1;imax) + if (cArr[i] == '?' && cArr[l-i-1]=='?') { - max = c[i]; - m_idx = i; + cost += 2* ((oCost c[0]) + if((l&1)==1) { - - // swap 1 st and max elem - char tc = c[0]; - c[0] = c[m_idx]; - c[m_idx] = tc; - + cost += (oCostmax ? attributes[i] : max; } - else + System.out.println("max - "+max); + + for(int i=0;i