S

@Shobh89

Missing and Repeating in an Array(Making Two Math Equations)

C++
1 year ago
#include <bits/stdc++.h> using namespace std; void repeatedNumber(const vector<int> &arr) { int n = arr.size(); int s = (n * (n + 1)) / 2; int ssq = (n * (n + 1) * (2 * n + 1)) / 6; int missing = 0, repeating = 0;

Missing and Repeating in an Array(In-Place and Sum Formula)

C++
1 year ago
#include <iostream> #include<vector> using namespace std; void printTwoElements(vector<int>&arr) { int n=arr.size(); int missing=(n*(n+1))/2; cout<<"Repeating ";

Missing and Repeating in an Array(Using Visited Array:)

C++
1 year ago
#include <iostream> #include<vector> using namespace std; void printTwoElements(vector<int>&arr){ int n=arr.size(); //Creating visited vector of size n+1 with //initial values are false. Note that array //values will go upto n,that is why we

Pair Sum(Brute Force)

C++
1 year ago
#include <iostream> #include<vector> using namespace std; vector<int>pairSum(vector<int>nums,int target){ vector<int>ans; int n=nums.size(); int i=0,j=n-1;

Pair Sum(Brute Force)

C++
1 year ago
#include <iostream> #include<vector> using namespace std; vector<int>pairSum(vector<int>nums,int target){ vector<int>ans; int n=nums.size(); for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){

Maxium subarray sum

C++
1 year ago
#include <iostream> #include<climits> using namespace std; int main() { int n=5; int arr[5]={1,2,3,4,5}; int maxSum=INT_MIN;

Maximum Subarray

C++
1 year ago
#include <iostream> #include<vector> using namespace std; int main() { int n=5; int arr[5]={1,2,3,4,5}; for(int st=0;st<n;st++){ for(int end=st;end<n;end++){

Maximum and minimum of an array

C++
1 year ago
#include <iostream> #include <limits.h> using namespace std; int setmini(int A[],int N) { int mini=INT_MAX; for(int i=0;i<N;i++){ if(A[i] < mini){ mini=A[i];

reverse a Vector using STL in C++

C++
1 year ago
// C++ program to reverse Vector // using reverse() in STL #include <bits/stdc++.h> using namespace std; int main() { // Get the vector

C++ Program For Linear Search

C++
1 year ago
//C++ program for linear search #include <iostream> #include<vector> using namespace std; void search(vector<int>arr, int search_Element) { int left=0; int length=arr.size();

Intersection of Two-Sorted Arrays using Sets

C++
1 year ago
#include <bits/stdc++.h> using namespace std; // Function to find the intersection // of two arrays vector<int> Intersection(int arr1[], int arr2[], int n, int m) { set<int> st;

Print all Distinct ( Unique ) Elements in given Array

C++
1 year ago
//C++ program to print all distinct elements in a given array #include <iostream> using namespace std; void printDistinct(int arr[],int n) { //Pick all elements one by one for(int i=0;i<n;i++) { //Check if the picked element is already printed

h

C++
1 year ago
#include <iostream> using namespace std; int main() { int n,max,min,maxpos,minpos,temp; cout<<"\nEnter no of elements: "; cin>>n; int arr[n]; cout<<"Enter elements: \n"; for(int i=0;i<n;i++) cin>>arr[i];

C++ Program to Find Sum and Product of Array Elements

C++
1 year ago
#include<iostream> using namespace std; int main () { int arr[10], n, i, sum = 0, pro = 1; cout << "Enter the size of the array : "; cin >> n; cout << "\nEnter the elements of the array : "; for (i = 0; i < n; i++) cin >> arr[i];

f

C++
1 year ago
#include <iostream> using namespace std; int main() { int arr[10],n,i,sum=0;pro=1; cout<<"Enter size of the array"; cin>>n; cout<<"\nEnter the elements of array: "; for(i=0;i<n;i++) cin>>arr[i];

reverse an array

C++
1 year ago
#include <iostream> using namespace std; void reverseArray(int arr[],int sz){ int start=0 ,end=sz-1; while(start<end){ swap(arr[start],arr[end]); start++; end--;

linear Search

C++
1 year ago
#include <iostream> using namespace std; int linearSearch(int arr[],int sz,int target){ for(int i=0;i<sz;i++){ if(arr[i] == target){//Found return i; } } return -1;//Not found

g

C++
1 year ago
#include <iostream> #include<climits> using namespace std; int main() { int nums[]={5,15,22,-1,-15,-24}; int size=6; cin>>nums;

smallest and largest number in an array

C++
1 year ago
#include <iostream> #include<climits> using namespace std; int main() { int nums[]={5,15,22,-1,-15,-24}; int size=6; int smallest=INT_MAX; int largest=INT_MIN;

Write a program to reverse digits of a number

C++
1 year ago
#include <iostream> using namespace std; /* Iterative function to reverse digits of num*/ int reverseDigits(int num) { int rev_num=0; while(num>0){ rev_num=rev_num*10+num%10; num=num/10;