Sales by Match – 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++ Sales by Match HackerRank Solution
#include <bits/stdc++.h>
using namespace std;
using LINT = long long int;
using PII = pair<int,int>;
#define PB push_back
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
int socks[107];
int main() {
int n;
cin >> n;
REP(i,n){
int x;
cin>>x;
socks[x]++;
}
int ans = 0;
REP(i,107)ans+=socks[i]/2;
cout<<ans<<endl;
return 0;
}
Java Sales by Match HackerRank Solution
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner s = new Scanner(System.in);
int[] freq = new int[101];
int n = s.nextInt();
for(int i = 0; i < n; i++){
int x = s.nextInt();
freq[x]++;
}
int total = 0;
for(int i = 1; i < 101; i++){
total+=freq[i]/2;
}
System.out.println(total);
}
}
Python 3 Sales by Match HackerRank Solution
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the sockMerchant function below.
def sockMerchant(n, ar):
num = 0
for i in range(0,n):
gum = 1
for j in range(i+1,n):
if ar[i] == None:
continue
if ar[i] == ar[j] and gum ==1:
num = num + 1
gum = gum + 1
ar[j] = None
return num
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
ar = list(map(int, input().rstrip().split()))
result = sockMerchant(n, ar)
fptr.write(str(result) + '\n')
fptr.close()
JavaScript Sales by Match HackerRank Solution
function processData(input) {
//Enter your code here
var pInput = input.split('\n');
var n = pInput[0];
var pInput = pInput[1].split(' ');
var oddItems = {};
pInput.map(function (i) {
if(oddItems[i]) {
delete oddItems[i];
} else {
oddItems[i] = true;
}
})
console.log((n - Object.keys(oddItems).length)/2);
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});
C Sales by Match HackerRank Solution
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int n;
scanf("%d",&n);
int arr[101];
for(int i=0;i<101;i++){
arr[i]=0;
}
for(int i=0;i<n;i++){
int j;
scanf("%d",&j);
arr[j] += 1;
}
int total=0;
for(int i=0;i<101;i++){
if(arr[i]> 1){
if(arr[i] % 2 == 0) total += (arr[i] / 2);
else total += ((arr[i]-1) / 2);
}
}
printf("%d",total);
return 0;
}
Leave a comment below