Posts

Remove consonants from a string

Remove consonants from string Given a string s, remove all consonants and prints the string s that contains vowels only. Input : The first line of input contains integer T denoting the number of test cases. For each test case, we input a string. Output:  For each test case, we get a string containing only vowels .  If the string doesn't contain any vowels, then print "No Vowel" Constraints: 1<=T<=100 The string should consist of only alphabets. Examples: For Input: 2 HmlMqPhBfaVokhR wdTSFuI IvfHOSNv Your Output is: ao uI IO #include <iostream> using namespace std ; int main() {     int input;     cin >>input;     char x[ 100 ]={ '\0' };     for ( int i = 0 ;i<=input;i++)     {         x[ 0 ]= '\0' ;         cin . getline (x, 100 );               if (i!= 0 ) ...

Intersection point in Y shaped linked list

Image
There are two singly linked lists in a system. By some programming error the end node of one of the linked list got linked into the second list, forming a inverted Y shaped list. Write a program to get the point where two linked lists merge. Above diagram shows an example with two linked list having 15 as intersection point. Expected time complexity is O(m + n) where m and n are lengths of two linked lists Input: You have to complete the method which takes two arguments as heads of two linked lists.   Output: The function should return data value of a node where two linked lists merge.  If linked list do not merge at any point, then it shoudl return -1. Constraints: 1 <=T<= 50 1 <=N<= 100 1 <=value<= 1000 Example: Input: 2 2 3 2 10 20 30 40 50 5 10 2 3 0 10 20 30 40 50 First line is number of test cases. Every test case has four lines. First line of every test case contains three numbers, x (number of nodes before merge point in 1st list), y(...

Count number of nodes in linked list

Image
Given a linked list of size  N , your task is to complete the function  countNodesinLoop()  that checks whether a given Linked List contains loop or not and if loop is present then return the count of nodes in loop or else return 0. Input(to be used for Expected Output Only): Frist line of the input contains a single integer  T , denoting the number of test cases. Then  T  test case follows. The first line of each test case contains an integer  N  denoting the size of the linked list. Next line contains  N  space separated integers depecting the elements of the linked list. Last line of the test case contains an helper integer to build the loop. Output: For each test case the function must return the size of the loop in the linked list or else 0. Constraints: 1<=T<=100 1<=N<=500 Example: Input: 2 10 25 14 19 33 10 21 39 90 58 45 4 2 1 0 1 Output: 6 1

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...