Professional Documents
Culture Documents
HackerRank
CLOSE ADS Lonely Integer problem solution CLOSE ADS
In this HackerRank Lonely Integer problem solution, we have Given an array of integers,
where all elements but one occur twice, find the unique element.
Search
Subscribe To Channel
Programmingoneonone
YouTube 797
₹93 ₹34 ₹93 ₹72
Crafted with by TemplatesYard | Distributed by Blogger
Problem
CLOSE ADSsolution in Python. CLOSE ADS
Code
def lonelyinteger(a):
a = sorted(a)
if len(a) < 3:
return a[0]
elif a[0] != a[1]:
return a[0]
else:
return lonelyinteger(a[2:])
if __name__ == '__main__':
a = int(input())
b = map(int, input().strip().split(" "))
print(lonelyinteger(b))
HackerRank Diagonal
int n = in.nextInt(); Difference problem solution
int[] ai = new int[n]; March 23, 2021
int i, j;
HackerRank Simple Array Sum
int x = 0;
problem solution
boolean state; March 23, 2021
System.out.println(ai[x]);
}
}
int _a_size;
cin >> _a_size;
cin.ignore (std::numeric_limits<std::streamsize>::max(),
'\n');
vector<int> _a;
int _a_item;
for(int _a_i=0; _a_i<_a_size; _a_i++) {
cin >> _a_item;
_a.push_back(_a_item);
}
res = lonelyinteger(_a);
cout << res;
return 0;
}
Problem solution in C.
Code
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
int lonelyinteger(int a_size, int* a) {
int res = 0;
for(int i=0; i<a_size; i++){
res = res^a[i];
}
return res;
}
int main() {
int res;
_a[_a_i] = _a_item;
}
return 0;
}