Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Saturday, September 24, 2016

Compare the Triplets hackerrank solution in c





































C Code :

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
    int a[3],p=0,q=0;
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    int b[3];
    scanf("%d %d %d",&b[0],&b[1],&b[2]);
    for(int i=0;i<3;i++)
        {
        if(a[i]>b[i])
            p++;
        else if(b[i]>a[i])
            q++;
    }
    printf("%d %d",p,q);
    return 0;
}


Java Code:

void printCount(int a[], int b[], int n) {
int alicePoints = 0;
int bobPoints = 0;
for(int i=0;i<n;++i) {
if(a[i]<b[i])
++bobPoints;
else if(a[i]>b[i])
++alicePoints;
}
System.out.println(alicePoints+" "+bobPoints);
}










1 comment:

Stats