Ice Cream Parlor

Sort by

recency

|

973 Discussions

|

  • + 0 comments
    def icecreamParlor(m, arr):
        # Write your code here
        
        temp = {}
        
        for i in range(len(arr)):
            diff = m - arr[i]
            if temp.get(diff):
                return [temp.get(diff), i+1]
            else:
                temp[arr[i]] = i + 1
    
  • + 0 comments

    What if the input is like this 1 10 6 1 4 5 5 6 2 which contain two solutions do we give both or we just give the first solution.

  • + 0 comments
    public static List<Integer> icecreamParlor(int m, List<Integer> arr) {
        List<Integer> result = new ArrayList<>();
        for(int i=0;i<arr.size()-1;i++) {
            int diff = m-arr.get(i);
            int idx = arr.indexOf(diff);
            if(idx == i) {
                idx = arr.subList(i+1, arr.size()).indexOf(diff);
                if(idx != -1) idx = i+1+idx;
            }
            if(idx == -1) continue;
    
            result.add(i+1);
            result.add(idx+1);
            return result;
        }
        return result;
    }
    
  • + 0 comments

    There is inconsitent use of variable name, early on the question it named as m later on the passage, it is named as . Please be consistent.

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/WvLuA-LCsb0

    vector<int> icecreamParlor(int m, vector<int> arr) {
        map<int, int> mp;
        for (int i = 0; i < arr.size(); i++) {
            int complement = m - arr[i];
            if (mp.count(complement)) {
                return {mp[complement] + 1, i + 1};
            }
            mp[arr[i]] = i;
        }
        return {};
    }