Ice Cream Parlor

Sort by

recency

|

80 Discussions

|

  • + 0 comments

    why does O(N^2) pass with 100%?

  • + 0 comments

    The problems that have more than one "trip to the icream" per test case are effing BS. Shoving more than one assert into a test case is a horrific antipattern. And having to sort this sht out here with no debugger and the output going to god knows where effing sucks. I wouldn't give a sht except job interviews make me go to this stupid site. Ef you, authors, for shoving more than one test case into a test. Seriously.

  • + 0 comments

    Javascript Solution

    function icecreamParlor(m, arr) {
      for (let i = 0; i < arr.length; i++) {
        const remainder = m - arr[i];
        const secondIndex = arr.indexOf(remainder);
        if (secondIndex != -1 && secondIndex != i) {
          return [i+1, secondIndex+1].sort((a,b) => a - b);
        }
      }
    }
    
  • + 0 comments
    public static List<Integer> icecreamParlor(int m, List<Integer> arr) {
    // Write your code here
        Map<Integer, Integer> costVsIndex = new HashMap<>();
        List<Integer> result = new ArrayList<>();
        for(int i = 0; i< arr.size(); i++) {
            Integer remaining = m - arr.get(i);
            if(costVsIndex.containsKey(remaining)) {
                 result.add(costVsIndex.get(remaining) + 1);
                 result.add(i + 1);
            } else {
                costVsIndex.put(arr.get(i), i);
            }
        }
        return result;
    }
    

    }

  • + 0 comments

    I'll never understand the HackerRank trend of posting solutions in the discussion section let alone uncommented and unexplained solutions.

    My thoughts: * I considered a two-pointer solution but the array isn't pre-sorted so this would require a sort which adds n * log(n) or a custom sort/search

    • Alternatively, you can use memoisation (collect some info while traversing for later). You need to think about the complement of the current price and available money.

    • Don't forget that the array isn't unique, just the solution