Ice Cream Parlor – HackerRank Solution Java , Python 3, Python 2 , C , C++, Best and Optimal Solutions , All you need.
Solutions of Algorithms Data Structures Hard HackerRank:
Here are all the Solutions of Hard , Advanced , Expert Algorithms of Data Structure of Hacker Rank , Leave a comment for similar posts
1 Month Preparation Kit Solutions – HackerRank
C++ Ice Cream Parlor HackerRank Solution
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int tc, i, k, flag, x, y, sum, C, L, Li[10009];
scanf("%d", &tc);
while( tc-- )
{
flag=0;
scanf("%d %d %d", &C, &L, &Li[0]);
for(i=1; i<L; i++)
{
scanf("%d", &Li[i]);
sum=Li[0]+Li[i];
if(sum==C)
{
flag=1;
y=i+1;
}
}
if(flag) printf("1 %d\n", y);
else
{
for(i=1; i<L; i++)
{
for(k=i+1; k<L; k++)
{
sum=Li[i]+Li[k];
if(sum==C)
{
flag=1;
x=i+1;
y=k+1;
break;
}
}
if(flag) break;
}
printf("%d %d\n", x, y);
}
}
return 0;
}
Java Ice Cream Parlor HackerRank Solution
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- != 0){
int m = sc.nextInt();
int n = sc.nextInt();
int[] np = new int[n];
Map<Integer, Integer> map = new HashMap<>();
for(int i = 0; i < n ; i++){
np[i] = sc.nextInt();
if(map.containsKey(np[i]) == false)
map.put(np[i], i+1);
}
Arrays.sort(np);
int s = 0;
int e = n - 1;
while(s < e){
if(np[s] + np[e] > m){
e--;
} else if (np[s] + np[e] < m){
s++;
} else {
int i1 = map.get(np[s]);
int i2 = map.get(np[e]);
if(np[s] == np[e])
i2++;
System.out.printf("%d %d%n", Math.min(i1, i2), Math.max(i1, i2));
e--;
s++;
}
}
}
}
}
Python 3 Ice Cream Parlor HackerRank Solution
for i in range(int(input())):
target = int(input())
loop = int(input())
costs = input().split(" ")
cur = 0
done = False
for j in range(loop - 1):
for k in range(j+1, loop):
if(int(costs[j]) + int(costs[k]) == target):
print(str(j+1) + " " + str(k+1))
done = True
break;
if(done): break
JavaScript Ice Cream Parlor HackerRank Solution
C Ice Cream Parlor HackerRank Solution
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n,m;
scanf("%d",&n);
int i=0;
for(;i<n;i++)
{
int c ;
scanf("%d",&c);
scanf("%d",&m);
int data[m];
int j=0;
for(;j<m;j++)
{
scanf("%d",&data[j]);
//printf("%d ",data[j]);
}
int k=0;
for(j=0;j<m;j++)
{
for(k=j+1;k<m;k++)
{
if(data[j]+data[k]==c)
{
printf("%d %d\n",j+1,k+1);
goto flag;
}
}
}
flag:;
}
return 0;
}
{“mode”:”full”,”isActive”:false}
Leave a comment below