Sunidhi Bansal has Published 1085 Articles

Print numbers in descending order along with their frequencies

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

504 Views

Given with an array of int elements, the task is to arrange the elements in descending order and finding their occurrences.Input : arr[]={1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 7, 7} Output : 7 occurs: 2    6 occurs: 1    5 occurs: 1    4 ... Read More

Print matrix in antispiral form

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

411 Views

Given a 2d array of n*n and the task is to find the antispiral arrangement of the given matrixInput : arr[4][4]={1, 2, 3, 4,    5, 6, 7, 8,    9, 10, 11, 12    13, 14, 15, 16} Output: 10 11 7 6 5 9 13 14 15 16 ... Read More

Print matrix in diagonal pattern

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

446 Views

Given a 2d array of n*n and the task is to find the antispiral arrangement of the given matrixInput : arr[4][4]={1, 2, 3, 4,    5, 6, 7, 8,    9, 10, 11, 12    13, 14, 15, 16} Output : 1 6 11 16 4 7 10 13AlgorithmSTART Step ... Read More

Print an array with numbers having 1, 2 and 3 as a digit in ascending order

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

715 Views

Here, the task is to print those number in an array having 1, 2 and 3 as digits in their numbers and if their is no such number than the output must be -1Input : arr[] = {320, 123, 124, 125, 14532, 126, 340, 123400, 100032, 13, 32, 3123, 1100} ... Read More

Print prime numbers with prime sum of digits in an array

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

639 Views

Given with an array of elements and the task is to print those numbers whose digit sum is also prime and return -1 is not such digit exists in an arrayInput: arr[]={2, 4, 3, 19, 25, 6, 11, 12, 18, 7} Output : 2, 3, 25, 11, 12, 7Here, the ... Read More

Print numbers having first and last bits as the only set bits

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

242 Views

The task is to print the given n number which have exactly two set bits that neither less than 2 nor more than 2.Set bits in computer language are the one that have value 1 and unset bits have value as 0Input: value of num=5 Output: 1 3 5   ... Read More

Print Postorder traversal from given Inorder and Preorder traversals

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

1K+ Views

Given with inorder and preorder of a tree program must find the postroder traversal and print the sameInput: Inorder traversal in[] = {4, 2, 5, 1, 3, 6} Preorder traversal pre[] = {1, 2, 4, 5, 3, 6} Output: Postorder traversal post[] = {4, 5, 2, 6, 3, 1}AlgorithmSTART Step ... Read More

Print Reverse a linked list using Stack

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

1K+ Views

Given with a linked list program must print the list starting from the end till the front using the stack data structureInput : 10 -> 5 -> 3 -> 1 -> 7 -> 9 Output: 9 -> 7 -> 1 -> 3 -> 5 -> 10Here the user can use ... Read More

Print the nearest prime number formed by adding prime numbers to N

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

367 Views

As per the question, the task is to find the nearest prime number by adding the prime number starting from 2 if the number N is not Prime.Input: N=6 Output: 11ExplanationSince 6 is not prime add first prime to 6 i.e. 2 which will result to 8 now 8 is ... Read More

Print N lines of numbers such that every pair among numbers has a GCD K

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

211 Views

GCDGCD stands for Greatest Common Divisor of two or more integers excluding 0Like, to find the greatest common divisor of 48 and 18048 = 2 × 2 × 2 × 2 × 3180 = 2 × 2 × 3 × 3 × 5Greatest common divisor = 2 × 2 × ... Read More

Advertisements