Problem Description: Sort the given doubly linked list using quicksort. Just complete the partition function using quicksort techniquetry to solve it in O(1) space . Input: In this problem, method takes two argument: the node1 and node2. The function should not read any input from stdin/console. The struct Node has a data part which stores
Year: 2016
Given a linked list, reverse alternate nodes and append at the end
Description: Given a linked list,performs the following task Remove alternative nodes from second node Reverse the removed list. Append the removed list at the end. Input : You have to complete the method which takes oneargument: the head ofthe linked list. You should not read any input fromstdin/console. The struct Node has a data part
Continue Reading “Given a linked list, reverse alternate nodes and append at the end”
Reverse a Linked List in groups of given size
Problem Description: Given a linked list, write a function to reverse every k nodes (where k is an input to the function).Ifalinked list is givenas1->2->3->4->5->6->7->8->NULL and k = 3 then output will be3->2->1->6->5->4->8->7->NULL. Input: In this problem,method takes two argument: the head of the linked list and int k. You should not read any input
Continue Reading “Reverse a Linked List in groups of given size”
Delete nodes having greater value on right
Problem description: Given a singly linked list, remove all the nodes which have a greater value on right side. Input: You have to complete the method which takes 1argument: the head of the linked list .You should not read any input from stdin/console.There are multiple test cases. For each test case, this method will be
Continue Reading “Delete nodes having greater value on right”
Find the Intersection point of two Y-shaped LinkedList
Problem Link /* Link list Node struct Node { int data; struct Node* next; }; */ /* Should return data of intersection point of two linked lists head1 and head2. If there is no intersecting point, then return -1. */ int intersectPoint(struct Node* head1, struct Node* head2) { // Your Code Here int cnt1,cnt2,cnt; Node
Continue Reading “Find the Intersection point of two Y-shaped LinkedList”
Cloning a linkedlist
Problem Link /* the node structure is as follows struct Node { int data; Node* next; Node* arb; };*/ // Should return the head of the copied linked list the //output will be 1 if successfully copied Node * copyList(Node *head) { // Your code here Node *chead=new Node; Node *tmp,*nNode,*a; Node *arr[101]; int val;
Flattening a Linked List
Problem Description: Given a Linked List where every node represents a linked list and contains two pointers of its type: (i) a next pointer to the next node (ii) abottompointerto a linked list where this node is head. You have to flatten the linked list to a single linked list which is sorted. For Ex:
Merge K sorted LinkedList into one sorted LinkedList
Problem Link /*Linked list node structure struct node { int data; struct node* next; };*/ /*You are required to complete this function*/ node * mergeKList(node *arr[],int N) { //Your code here node *headArray[11]; node *tmpNodes[11]; node *newHead,*tmp,*t; for(int i=0;i<=N;i++) { tmpNodes[i]=arr[i]; } bool f=1; bool first=0; while(f) { int min=10000000; int lastIdx=-1; f=0; for(int i=0;i<=N;i++)
Continue Reading “Merge K sorted LinkedList into one sorted LinkedList”
Binary to decimal conversion from a linkedlist binary data stream.
/* Below global variable is declared in code for modulo arithmetic const long long unsigned int MOD = 1000000007; */ /* Link list Node/ struct Node { bool data; // NOTE data is bool struct Node* next; }; */ // Should return decimal equivalent modulo 1000000007 of binary linked list long long unsigned int decimalValue(struct
Continue Reading “Binary to decimal conversion from a linkedlist binary data stream.”
Find the square root of a number,Use binary search
long long int floorSqrt(long long int x) { // Your code goes here int lo=0,hi=1000,mid; while(hi-lo>=1) { mid=(lo+hi)/2; if(mid*mid<x) lo=mid+1; else if(mid*mid>x) hi=mid-1; else return mid; } if(lo*lo>x) return lo-1; else return lo; }