Posts

Showing posts from October, 2018

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