PFR192 Pe Su2023
PFR192 Pe Su2023
Problem 1:
Given an unsorted array A of size N that contains only positive integers, find a continuous sub-
array that adds to a given number S and return the left and right index(1-based indexing) of
that subarray.
In case of multiple subarrays, return the subarray indexes which come first on moving from left
to right.
Note:- You have to return an ArrayList consisting of two elements left and right. In case no
such subarray exists return an array consisting of element -1.
Example 1: Example 2:
Input: Input:
N = 5, S = 12 N = 10, S = 15
A[] = {1,2,3,7,5} A[] = {1,2,3,4,5,6,7,8,9,10}
Output: 2 4 Output: 1 5
/*Explanation: The sum of elements /* Explanation: The sum of elements
from 2nd position to 4th position from 1st position to 5th position
is 12. */ is 15. */
Problem 2:
Given an array A of positive integers. Your task is to find the leaders in the array. An element of
array is leader if it is greater than or equal to all the elements to its right side. The rightmost
element is always a leader.
Example 1:
Explanation:
Input:
Since, each element in {1,2,3} appears only once so there is no
N=3
majority element.
A[] = {1,2,3}
Output:
-1
Example 2:
Input: Explanation:
Problem 3:
Given an expression string x. Examine whether the pairs and the orders of {,},(,),[,] are correct
in exp.
For example, the function should return 'true' for exp = [()]{}{[()()]()} and 'false' for exp = [(]).
Note: The drive code prints "balanced" if function return true, otherwise it prints "not
balanced".
Example 1:
Input: Explanation:
{([])} { ( [ ] ) }. Same colored brackets can form
Output: balanced pairs, with 0 number of
true unbalanced bracket.
Example 2:
Explanation:
(). Same bracket can form balanced pairs,
and here only 1 type of bracket is
present and in balanced way.
Example 3:
Input: Explanation:
([] ([]. Here square bracket is balanced but
Output: the small bracket is not balanced and
false Hence , the output will be unbalanced.
Your Task:
This is a function problem. You only need to complete the function ispar() that takes a string as
a parameter and returns a boolean value true if brackets are balanced else returns false.
The printing is done automatically by the driver code.
Problem 4:
Given an array A of n positive numbers. The task is to find the first Equilibrium Point in an
array.
Equilibrium Point in an array is a position such that the sum of elements before it is equal to
the sum of elements after it.
Example 1:
Input: Explanation:
Example 2:
Input: Explanation:
Your Task:
The task is to complete the function equilibriumPoint() which takes the array and n as input
parameters and returns the point of equilibrium. Return -1 if no such point exists.
Problem 4:
Given an array Arr of size N, print second largest distinct element from an array.
Example 1:
Your Task:
You don't need to read input or print anything. Your task is to complete the
function print2largest() which takes the array of integers arr and n as parameters and returns an
integer denoting the answer. If 2nd largest element doesn't exist then return -1.
Problem 5:
Given an array of string literals, reverse the array.
Examples:
Input : arr[] = {"Coding", "Never", "Fail", "Me"}
Output : arr[] = {"Me", "Fail", "Never", "Coding"}
Problem 6:
Floyd’s triangle is a triangle with first natural numbers. Task is to print reverse of Floyd’s
triangle.
Examples:
Input : 5
Input : 4
Output :
Output :
15 14 13 12 11
10 9 8 7
10 9 8 7
6 5 4
6 5 4
3 2
3 2
1
1
Problem 7:
Given the value of length, print the crown pattern using ‘*’ and ‘#’.
Note : In order to print a perfect crown, take the value of length as an odd number greater
than 15.
Examples: Input: length = 19
Output:
* * *
Input: length = 25
# # #
Output: ###
## ##
*
### #####* ###
*
#### ####### ####
# #
###################
#
###################
## ###
##
###################
### #####
*******************
###
#### #######
####