0% found this document useful (0 votes)
11 views1 page

Sample Programming Questions - SET 2

The document contains three programming problems: 1) Print a pattern of numbers in a specific format given an input number. 2) Replace each number in an array with the next greater number present in the remaining elements. 3) Find all pairs of elements in an unsorted array that have the smallest absolute difference.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Sample Programming Questions - SET 2

The document contains three programming problems: 1) Print a pattern of numbers in a specific format given an input number. 2) Replace each number in an array with the next greater number present in the remaining elements. 3) Find all pairs of elements in an unsorted array that have the smallest absolute difference.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Programming Test

1. Write a program to print the below pattern.

Input: 5
Output:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

2. Write a program to traverse an array from left to right and replace each number with
the next greater number present within the remaining elements from its position. For
example, from (4, 9, 23, 7) the next greater number to 4 is 7. If no such number is
found, then replace the remaining array elements with -1.

Examples:
Input: 2,5,7
Output: 5,7,-1
Input: 2,4,8,90,77,54
Output: 4,8,54,-1,-1,-1
Input: 2,-1,0,-1,3
Output: 3,0,3,3,-1

3. From the given unsorted integer array, find the pair(s) of elements that have the
smallest absolute difference between them. If there are multiple such pairs then find
them all.

Examples:
Input: [20, 30, 120, 240]
Output: [20, 30]
Input: [5, 4, 3, 2]
Output: [2, 3], [3, 4], [4, 5]
Input: [11, 15, 24, 9]
Output: [11, 9]

You might also like