Posts

Showing posts from July, 2018

delete the node without the head node

You are given a pointer/reference to a node to be deleted in a linked list. The task is to delete the node.  Pointer/reference to head node is not given.  You may assume that the node to be deleted is not the last node. Input: You have to complete a method which takes one argument: pointer/reference to a node to be deleted.  There are multiple test cases. For each test case, this method will be called individually. Example: Input 2 2 1 2 1 4 10 20 4 30 20 20 Output 2 10 4 30 A  simple solution  is to traverse the linked list until you find the node you want to delete.  But this solution requires pointer to the head node which contradicts the problem statement. Fast solution  is to copy the data from the next node to the node to be deleted and delete the next node. Something like following. // Find next node using next pointer struct Node *temp = node_ptr->next; // Copy data of next node to this node ...

Multiply Two linked list

You have given two linked list of maximum size of 100 You have to do multiply operation on linked list and produce output Note:- use long long int to handle large number and perform modulo 10^9+7 inorder to make the number of proper size Example(To be used only for expected output): Input 2 2 3 2 1 2 3 1 0 0 2 1 0   Output 64 1000 The solution is as follows:- Hints 1 do modulo operation on each number during joining 2 multiply two numbers and do modulo on it too otherwise its range will be ove rflow 3 so formula will become somewhat like this num3=((num1%10^9+7)*(num2%10^9+7))    %(10^9+7) Code:-  1 {    2     3 #include<bits/stdc++.h>    4     5 using namespace std;    6     7      8     9 /* Linked list Node */   10    11 struct Node   12   13 {  14   15...