Definition: Write function to merge two sorted linked list without using any data structure. Solution: Both recursion and non-recursion uses concept of dummy pointer. Dummy pointers are usually added at start or end of the of linked list. Dummy node gives something to point at when initially result list is empty. After building result set [...]
Merge two sorted linked list without using any external data structure
An array with random 0s and non 0 numbers is given, shift all the 0s to the beginning and non 0s to the rear, without using any external data structure
Definition: Array with random 0s and non 0 numbers is given, write program to shift all the 0s to the beginning of the array and non 0s to the rear. Also order of the non 0 numbers should not be change. For e.g. input array Then output should be In output array all the 0s [...]
Find the starting point of loop in cyclic linked list
Definition: For the given singly linked list need to find starting point of the loop (cycle) As shown in figure linked list contains loop and loop starts from node 3. Algorithm: Using the Floyd Cycle algorithm find meeting point of the first and second pointer. Once find the meeting node reset the first pointer to [...]
Merge the 2 sorted array, first array has enough space for store the second array
Definition: Two sorted array and no of elements in the first array is given, first array has enough space to store second array. Write java function to merge these two sorted array (sorting order). e.g. Arr1 = Arr2 = As shown in above figure, first array contains only 5 elements, but it has enough space [...]
Given a sorted but rotated Linked List, Find its starting point
Definition: Sorted (acceding order) but rotated singly linked list given, write program to find starting point (Node with smallest value). Ex: 8 9 10 4 5 6 7 8 Linked list on the above figure is sorted but rotated, So originally starting point is 4 for above linked list. Algorithm: Start iterating the linked list [...]
Print the data of the singly linked list in reverse order
Definition: Write function to print singly linked list data in reverse order. For e.g If above linked list is given then output should be 5, 4, 3, 2, 1 Solution: This problem can be solved by three ways. Iterate the linked list recursively, when reach at the end of the list (while you start unwinding) [...]
Convert string to lowercase
Definition: A string in any case(capital, small) is given, write function to convert string to lower case.For e.x. THIS is UPPER CASE. o/p : this is upper case. Algorithm: Iterate the string and get the ASCII value related to each character If the character is not within range of the ASCII value of upper case [...]
Reverse given array without using iteration
Definition: Write function to reverse a given array without iteration. For e.g. Input array Output array Algorithm: If iteration is not allowed then second method to traverse array is using recursion. With recursion we can reverse array same way as we reverse string. Check for the valid input array Call private recursive function with start [...]
Convert given string to uppercase
Definition: A string in any case(capital, small) is given, write function to convert string to uppercase (capital letter). For e.x. adfhi8994 o/p: ADFHI8994 Algorithm: Iterate the string and get the ASCII value related to each character If the character is not within range of the ASCII value of lower case letters then skip it (As [...]
Check that the given element is in the sorted matrix or not
Definition: Sorted mxn matrix is given, where all the rows and columns are in increasing order. Now any number ‘x’ is given. Write program to check that this number ‘x’ is present in matrix or not. For e,g,Below is sorted nxn matrix 2 4 6 7 9 10 13 16 19 39 40 45 50 [...]
Print maximum sub sequence sum of an integer array
Definition: Write program to find maximum sub sequence sum of array integers, array can contains the positive or negative values. In other words we need to find a contiguous range of integers in the array that has the largest sum. For e.g. 4 8 -13 0 1 4 6 For above array, contiguous are 0, [...]
Convert roman string to integer value
Definition: Write java function to convert roman number string to integer number. For e.g. Input roman number= “XLVI” Output integer number= 64 Solution: There are some predefined integer values equivalent of all the single-letter Roman numerals. M 1000 X 10 D 500 V 5 C 100 I 1 L 50 When letters are strung together, [...]
Convert HEX string to integer value
Definition: Write a function to convert HEX string to integer value. For e.g. HEX string “22D2B” equals integer number is 142635 Solution: Convert string to lowercase (To avoid conflict for a-f char in hex ) Check for “0X” chars in start, If they presents then set start index to 2 Iterate the string from end [...]
