Hot Topics

Persistent Solution
Technical Round
#include<iostream>
using namespace std;
class Node{
public:
int data;
Node* next;
Node(int d){
this->data=d;
this->next=NULL;
}
};
void insertAtTail(Node* &head, int val) {
Node* n = new Node(val);
if(head==NULL) {
head=n;
return;
}
Node* temp = head;
while(temp->next!=NULL) {
temp=temp->next;
}
temp->next = n;
}
void print(Node* &head) {
Node* temp = head;
while(temp != NULL ) {
cout < data < next;
}
cout <next);
cout<data<<" ";
}
int main() {
Node* node = new Node(10);
Node* head = node;
insertAtTail(head,20);
insertAtTail(head,30);
insertAtTail(head,40);
print(head);
reverse(head);
return 0;
}
/*
output:
10 20 30 40
40 30 20 10
*/
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cout<<"Enter the value"<<endl;
cin>>n;
if(n==0){
cout<<"The number is not power of 2."<<endl;
return false;
}
while(n!=1){
if(n%2 != 0){
cout<<"The number is not power of 2."<<endl;
return false;
}
n=n/2;
}
cout<<"The number is power of 2."<<endl;
return 0;
}
/*
output:
Enter the value
9
The number is not power of 2.
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
sort(arr,arr+n);
cout<<"Largest Element: "<<arr[n-1]<<endl;
return 0;
}
/*
outuput:
5
1 7 8 2 14
Largest Element: 14
/




Popular Category
Hot Topics
Go through our study material. Your Job is awaiting.