Skip to content

Instantly share code, notes, and snippets.

View hiteshchopra11's full-sized avatar

Hitesh Chopra hiteshchopra11

View GitHub Profile
@hiteshchopra11
hiteshchopra11 / duplicate_hashing.cpp
Last active February 24, 2021 19:53
Duplicate number using hashing
#include <bits./stdc++.h>
using namespace std;
int duplicate_hashing(int arr[], int n)
{
//Create a boolean value of size n
bool flag[n];
//Set all values of flag boolean array initially as false
fill(flag, flag + n, false);
@hiteshchopra11
hiteshchopra11 / duplicate_sorting.cpp
Created February 24, 2021 16:05
Find duplicate element using Sorting approach
#include <bits/stdc++.h>
using namespace std;
int sorting_duplicate(int arr[], int n)
{
//Sort the array using STL sort function or write own sorting algorithm(merge sort or heap sort)
sort(arr, arr + n);
for (int i = 1; i < n; i++)
{
//As the list is sorted,if two consecutive values are found, return the value as it is duplicate