Lonely Integer

Problem Statement :

```Given an array of integers, where all elements but one occur twice, find the unique element.

Example
a = [1,2,3,4,3,2,1]
The unique element is 4.

Function Description

Complete the lonelyinteger function in the editor below.

lonelyinteger has the following parameter(s):

int a[n]: an array of integers
Returns

int: the element that occurs only once
Input Format

The first line contains a single integer, n, the number of integers in the array.
The second line contains n space-separated integers that describe the values in a.

Constraints
1 <= n < 100
It is guaranteed that n is an odd number and that there is one unique element.
0 <= a[i] <= 100, where 0 <= i < n.```

Solution :

```                            ```Solution in C :

In C++ :

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
int lonelyinteger(vector < int > a) {
int ans=0;
vector<int> ::iterator it;
for(it=a.begin();it!=a.end();it++)
{
ans^=(*it);
}
return ans;

}
int main() {
int res;

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;
}

In Java :

import java.util.StringTokenizer;
import java.io.IOException;

public class Solution{
public static void main(String[] args) throws IOException {
try {
boolean arr[] = new boolean[101];
for (int i = 0; i < N; i++) {
int a = Integer.parseInt(st.nextToken());
arr[a] = !arr[a];
}
for (int i = 0; i < 101; i++) {
if(arr[i]) {
System.out.println(i);
break;
}
}
}
catch(Exception e) {
}
}
}

In C :

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
int lonelyinteger(int a_size, int* a) {
int i=0;
int num=0;
for(i=0;i<a_size;i++){
num=num^a[i];
}

return num;

}
int main() {
int res;

int _a_size, _a_i;
scanf("%d", &_a_size);
int _a[_a_size];
for(_a_i = 0; _a_i < _a_size; _a_i++) {
int _a_item;
scanf("%d", &_a_item);

_a[_a_i] = _a_item;
}

res = lonelyinteger(_a_size, _a);
printf("%d", res);

return 0;
}

In Python3 :

n=int(input())
a=list(map(int,input().split()))
r=a[0]
for i in range(1,n):
r=r^a[i]
print(r)```
```

Print in Reverse

Given a pointer to the head of a singly-linked list, print each data value from the reversed list. If the given list is empty, do not print anything. Example head* refers to the linked list with data values 1->2->3->Null Print the following: 3 2 1 Function Description: Complete the reversePrint function in the editor below. reversePrint has the following parameters: Sing

Given the pointer to the head node of a linked list, change the next pointers of the nodes so that their order is reversed. The head pointer given may be null meaning that the initial list is empty. Example: head references the list 1->2->3->Null. Manipulate the next pointers of each node in place and return head, now referencing the head of the list 3->2->1->Null. Function Descriptio

You’re given the pointer to the head nodes of two linked lists. Compare the data in the nodes of the linked lists to check if they are equal. If all data attributes are equal and the lists are the same length, return 1. Otherwise, return 0. Example: list1=1->2->3->Null list2=1->2->3->4->Null The two lists have equal data attributes for the first 3 nodes. list2 is longer, though, so the lis