HackerRank Migratory Birds Problem Solution in C
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int n;
scanf("%d",&n);
int *types = malloc(sizeof(int) * n);
for(int types_i = 0; types_i < n; types_i++){
scanf("%d",&types[types_i]);
}
int c[5] = {0};
for (int i=0; i<n; i++){
c[types[i]-1]++;
}
int max = -1;
int maxi = -1;
for (int i=0; i<5; i++) {
if(c[i]>max){
max = c[i];
maxi = i;
}
}
printf("%d\n", maxi+1);
// your code goes here
return 0;
}
HackerRank Migratory Birds Problem Solution in JavaScript
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
/////////////// ignore above this line ////////////////////
function main() {
var n = parseInt(readLine()),
types = readLine().split(' ');
types = types.map(Number);
// your code goes here
var occ = [0,0,0,0,0],
max_occ = 0,
ans = 0
for (var i = 0 ; i < types.length ; i++) occ[types[i]-1]++
for (var i = 0 ; i < 5 ; i++) if (occ[i] > max_occ) max_occ = occ[i], ans = i
//console.error(occ)
console.log(ans + 1)
}
HackerRank Migratory Birds Problem Solution in Python
#!/bin/python3
import sys
n = int(input().strip())
types = list(map(int, input().strip().split(' ')))
# your code goes here
counter = [0 for ii in range(5)]
for t in types:
counter[t-1] += 1
hf = 0
for nth, c in enumerate(counter[1:], start=1):
if c > counter[hf]:
hf = nth
print(hf+1)
HackerRank Time Conversion Problem Solution in C#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 */
char time[10];
int hr1,hr2,hr3,hr,min,sec,i;
scanf("%s",time);
if(time[8]=='A')
{
if(time[0]=='1'&&time[1]=='2')
{
time[0]='0';
time[1]='0';
}
for(i=0;i<8;i++)
printf("%c",time[i]);
}
else if(time[8]=='P')
{
hr1=time[0]-'0';
hr2=time[1]-'0';
hr3=hr1*10+hr2;
hr=12+hr3;
if(hr==24)
hr=12;
printf("%d",hr);
for(i=2;i<8;i++)
printf("%c",time[i]);
}
return 0;
}
HackerRank Time Conversion Problem Solution in JavaScript
function processData(input) {
//Enter your code here
if(input.indexOf('PM') !== -1) {
input = input.replace('PM', '');
var data = input.split(':');
var hour = parseInt(data[0], 10);
if(hour !== 12) {
hour += 12;
}
data[0] = hour;
console.log(data.join(':'));
} else {
input = input.replace('AM', '');
var data = input.split(':');
var hour = parseInt(data[0], 10);
if(hour === 12) {
hour = 0;
}
data[0] = hour < 10 ? '0' + hour : hour;
console.log(data.join(':'));
}
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});
HackerRank Time Conversion Problem Solution in Python
inS = input()
if (inS[0:2] == '12'):
if (inS[8:] == 'AM'):
hrs = int(inS[0:2])
hrs = hrs - 12
hrs = str(hrs) + '0'
outS = hrs + inS[2:8]
print(outS)
else:
print(inS[0:8])
elif (inS == '12:00:00PM'):
print('12:00:00')
elif (inS[8:] == 'AM'):
print(inS[0:8])
else:
hrs = int(inS[0:2])
hrs = hrs + 12
outS = str(hrs) + inS[2:8]
print(outS)