@@ -0,0 +1,1814 @@
+package com.freetymekiyan.algorithms.other;%0A%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0A%0A/**%0A * Suppose you are a salesman who travel around for business. Given n cities, for city i you can do business Ci times.%0A * If you cannot go to the same city the next day. Find the maximum days you can do business.%0A * %3Cp%3E%0A * Example 1:%0A * Input: %5B7, 3, 2%5D%0A * Output: 11%0A * %3Cp%3E%0A * Example 2:%0A * Input: %5B1000, 1, 1, 1%5D%0A * Output: 7%0A */%0Apublic class MaxSales %7B%0A%0A    public int maxSalesTime(int%5B%5D c) %7B%0A        if (c == null %7C%7C c.length == 0) %7B%0A            return 0;%0A        %7D%0A        if (c.length == 1) %7B%0A            return c%5B0%5D %3E 0 ? 1 : 0;%0A        %7D%0A        int n = c.length;%0A        int max = 0;%0A        int index = -1;%0A        while (true) %7B%0A            int curMax = 0;%0A            int curSecMax = 0;%0A            int curIdx = -1;%0A            int curSecIndx = -1;%0A            for (int j = 0; j %3C n; j++) %7B%0A                if (curIdx == -1) %7B%0A                    curMax = c%5Bj%5D;%0A                    curIdx = j;%0A                %7D else if (c%5Bj%5D %3E curMax) %7B%0A                    curSecMax = curMax;%0A                    curSecIndx = curIdx;%0A                    curMax = c%5Bj%5D;%0A                    curIdx = j;%0A                %7D else if (c%5Bj%5D %3E curSecMax) %7B%0A                    curSecMax = c%5Bj%5D;%0A                    curSecIndx = j;%0A                %7D%0A            %7D%0A            index = index == curIdx ? curSecIndx : curIdx;%0A            if (index == -1) %7B%0A                break;%0A            %7D%0A            c%5Bindex%5D--;%0A            max++;%0A        %7D%0A        return max;%0A    %7D%0A%0A    @Test%0A    public void testExamples() %7B%0A        MaxSales m = new MaxSales();%0A        int%5B%5D c = %7B1000, 1, 1, 1%7D;%0A        Assert.assertEquals(7, m.maxSalesTime(c));%0A        c = new int%5B%5D%7B7, 3, 2%7D;%0A        Assert.assertEquals(11, m.maxSalesTime(c));%0A    %7D%0A%7D%0A

add Max Sales