Join Regular Classroom : Visit ClassroomTech

Persistent Overall Interview Question + Coding Solutions – codewindow.in

Hot Topics

Persistent Solution

Technical Round

#include<iostream>
using namespace std;

class Node{
    public:
    int data;
    Node* next;
    Node(int d){
        this-&gt;data=d;
        this-&gt;next=NULL;
    }
};

void insertAtTail(Node* &amp;head, int val) {
    Node* n = new Node(val);
    
    if(head==NULL) {
        head=n;
        return;
    }
    
    Node* temp = head;
    while(temp-&gt;next!=NULL) {
        temp=temp-&gt;next;
    }
    temp-&gt;next = n;
}

void print(Node* &amp;head) {
    Node* temp = head;
    while(temp != NULL ) {
        cout &lt; data &lt; next;
    }
    cout &lt;next);
    
    cout&lt;data&lt;&lt;&quot; &quot;;
}

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
/

      

Go through our study material. Your Job is awaiting.

Recent Posts
Categories