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

Problem Set 4

The document outlines Problem Set 4 focused on Arrays and Strings, presenting six programming problems to solve. Each problem includes a description, input examples, and expected output, covering tasks such as array rotation, identifying leaders in an array, maximizing subsequence sums, sorting by frequency, segregating binary arrays, and constructing a product array without division. This set is designed for training in data structures and algorithms.

Uploaded by

Akhilesh Bhadana
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)
2 views1 page

Problem Set 4

The document outlines Problem Set 4 focused on Arrays and Strings, presenting six programming problems to solve. Each problem includes a description, input examples, and expected output, covering tasks such as array rotation, identifying leaders in an array, maximizing subsequence sums, sorting by frequency, segregating binary arrays, and constructing a product array without division. This set is designed for training in data structures and algorithms.

Uploaded by

Akhilesh Bhadana
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

Problem Set 4: Arrays and Strings Data structure and Algorithm Training

Data Structure and Algorithms

Problem Set 4: Arrays and Strings

Date of issue: Due Date:

Problem 1) Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements.


Input: - e.g. input an array with n=7 elements are 1 2 3 4 5 6 7 and rotation d=2 the output
Output: - 3 4 5 6 7 1 2

Problem 2) Write a program to print all the LEADERS in the array. An element is leader if it is
greater than all the elements to its right side. And the rightmost element is always a leader.
Input: - 16, 17, 4, 3, 5, 2
Output: - leaders are 17, 5, 2

Problem 3) Given an array of positive numbers, find the maximum sum of a subsequence with
the constraint that no 2 numbers in the sequence should not be adjacent in the array.

Sr. No. Input Output

1 3 2 7 10 13 (sum of 3 and 10)

2 3 2 5 10 7 15 (sum of 3, 5 and 7)

Problem 4) Print the elements of an array in the decreasing frequency if 2 numbers have same
frequency then print the one which came first.

Sr. No. Input Output

1 2, 5, 2, 8, 5, 6, 8, 8 8, 8, 8, 2, 2, 5, 5, 6

2 2, 5, 2, 6, -1, 9999999, 5, 8, 8, 8 8, 8, 8, 2, 2, 5, 5, 6, -1, 9999999

Problem 5) You are given an array of 0s and 1s in random order. Segregate 0s on left side and
1s on right side of the array. Traverse array only once
Input: - 0, 1, 0, 1, 0, 0, 1, 1, 1, 0
Output: - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1

Problem 6) Given an array arr[] of n integers, construct a Product Array prod[] (of same size)
such that prod[i] is equal to the product of all the elements of arr[] except arr[i]. Solve it without
division operator and in O(n)
Input: - arr[] = {10, 3, 5, 6, 2}
Output: - prod[] = {180, 600, 360, 300, 900}

Akhilesh Deep Arya Page | 1

You might also like