0% found this document useful (0 votes)
2 views

Offline 2

The document outlines two programming problems related to arrays: finding the most frequently occurring element and performing a circular shift on an array. For the first problem, the output should include the most frequent number and its count, while the second problem requires shifting the array elements based on a specified amount. Submission guidelines are provided, emphasizing adherence to input/output formats and prohibiting copying from external sources.

Uploaded by

udoyroy101
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 views

Offline 2

The document outlines two programming problems related to arrays: finding the most frequently occurring element and performing a circular shift on an array. For the first problem, the output should include the most frequent number and its count, while the second problem requires shifting the array elements based on a specified amount. Submission guidelines are provided, emphasizing adherence to input/output formats and prohibiting copying from external sources.

Uploaded by

udoyroy101
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/ 4

CSE110

Offline 2: Array

Problem 1: Most Occurring Element

Problem Statement

You are given a sequence of integers. Find the number that appears most
frequently in the array and print the number followed by its count. If multiple
numbers have the same maximum frequency, print the number with the first
occurrence in the array.

Input Format

●​ First line: an integer n — the number of input numbers.


●​ Second line: n space-separated integers.

Output Format

●​ Print two space-separated integers: the most frequent number and its count.

Sample Input No-1


5
1 2 3 3 2

Sample Output No-1


2 2

Sample Input No-2


6
1 2 3 2 3 3
Sample Output No-2
3 3

Explanation for Sample IO No-1

The goal is to find the number with the highest frequency in the array and its count.
If there’s a tie, choose the number that appears first in the array.

●​ Input array: In the sample input [1, 2, 3, 3, 2]: - Number 1 appears 1


time. - Number 2 appears 2 times. - Number 3 also appears 2 times.
●​ Frequencies: The highest frequency is 2 (for number 2 & 3).
●​ Tie handling: As numbers 2 and 3 both had a frequency of 2 we’d choose 2
because its first occurrence (index 1) is earlier than 3’s.
●​ Output: 2 2.

Problem 2: Array Circular Shifting

Problem Statement

You are given a sequence of numbers and a shift amount. Perform a circular shift
on the array.​
A positive shift amount indicates a right circular shift, and a negative shift
amount indicates a left circular shift.

A circular shift moves all elements in the array by a specified number of positions,
with elements wrapping around to the opposite end if they fall off the array.

●​ Positive shift (k > 0): Right circular shift. Each element moves k positions
to the right. Elements that exceed the array's end wrap around to the
beginning.
●​ Negative shift (k < 0): Left circular shift. Each element moves |k|
positions to the left. Elements that fall below index 0 wrap around to the end.
Input Format

●​ First line: an integer n — the number of input numbers.


●​ Second line: n space-separated integers.
●​ Third line: an integer k — the shift amount (positive for right shift, negative
for left shift).

Output Format

●​ Print n space-separated integers — the array after performing the circular


shift.

Sample Input No-1


5
1 2 3 4 5
2

Sample Output No-1

4 5 1 2 3

Sample Input No-2


5
1 2 3 4 5
-6

Sample Output No-2

2 3 4 5 1
Explanation for Samle IO No-1

Original: 1 → 2 → 3 → 4 → 5
Shift amount: k = 2 (right shift)
Step: Move each element 2 positions right circularly
Result: 4 → 5 → 1 → 2 → 3

Submission Guideline:​

1.​ Create a folder using your roll number. Example: 2406xyz


2.​ Create a file named 1.c and solve problem 1 there.
3.​ Create another file named 2.c and solve problem 2 there.
4.​ Now, remove unnecessary files. The 2406xyz should contain only 1.c and 2.c
files.
5.​ Zip it using name 2406xyz.zip
6.​ Submit it in the moodle.

Please do not copy from any sources (friends, internet, AI tools like
ChatGPT, etc.). Doing so will result in a -100% penalty.
Students must strictly follow the input and output format. Do not
include any extra print statements, as they may cause the solution
to be rejected. Also follow the submission guideline.

You might also like