We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Search
- Ice Cream Parlor
- Discussions
Ice Cream Parlor
Ice Cream Parlor
Sort by
recency
|
953 Discussions
|
Please Login in order to post a comment
Here is my c++ solution, you can watch the explanation here : https://youtu.be/WvLuA-LCsb0
JAVA
import java.util.Scanner; import java.util.HashMap; public class Solution { public static void main(String[]args) { Scanner scan=new Scanner(System.in); int t=scan.nextInt(); while (t-->0) { int m=scan.nextInt(); int n=scan.nextInt(); int[]costs=new int[n]; for(int i=0;imap=new HashMap(); for (int i=0;i int otherCost=money-cost; if (map.containsKey(otherCost)) { System.out.println(map.get(otherCost)+" "+icecreamID); } map.putIfAbsent(cost,icecreamID); } } }
Python
using a hash_map in a simple O(n) sol