0% found this document useful (0 votes)
4 views8 pages

Arrays Java

The document outlines various programming problems involving arrays, including a bus seat booking system, palindrome checking, student marks calculation, stock management, missing number identification, step count analysis, library book arrangement, and product price tracking. Each problem includes a problem statement, input/output format, and constraints. Sample inputs and outputs are provided for clarity.

Uploaded by

Ramya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Arrays Java

The document outlines various programming problems involving arrays, including a bus seat booking system, palindrome checking, student marks calculation, stock management, missing number identification, step count analysis, library book arrangement, and product price tracking. Each problem includes a problem statement, input/output format, and constraints. Sample inputs and outputs are provided for clarity.

Uploaded by

Ramya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ARRAYS

[Link] Seat Booking System

Problem Statement

A bus has N seats. Initially, all seats are empty (0).

 If a seat is booked → mark as 1


 If already booked → show message

Perform booking operations and display final seat status.

Input Format:

First line → Integer N (number of seats)

Next lines → Booking operations in the format:

Book: seat_number

Output Format:

For each booking:

→ "Seat X booked" (if seat is empty)

→ "Seat X already booked" (if seat is already occupied)

Final line:

→ "Final Seats: " followed by seat status (0 or 1 separated by space)

Constraints

1≤ N ≤ 50

Seat numbers start from 0 index

Sample Input

5
Book: 1
Book: 3
Book: 1

Sample Output

Seat 1 booked
Seat 3 booked
Seat 1 already booked
Final Seats: 0 1 0 1 0

[Link] Palindrome Array

Problem Statement

Write a Java program to check whether a given array is a palindrome (i.e., it reads the same
forward and backward).

 Create a separate method isPalindrome(int[] arr)


 Pass the array as an argument to the method
 The method should return true if the array is a palindrome, otherwise false

Input Format:

First line → Integer N (size of array)

Second line → N integers (array elements separated by space)

Output Format:

Print "Palindrome" if the array is same forward and backward

Otherwise print "Not Palindrome"

Constraints

 1 ≤ N ≤ 100
 Array elements range from -1000 to 1000

Sample Input 1

5
12321

Sample Output 1

Palindrome

Sample Input 2

5
12345

Sample Output 2

Not Palindrome
[Link] Statement
A teacher records the marks of N students in M subjects.
The marks are stored in a 2D array.
Rows → Students
Columns → Subjects
Write a program to calculate the total marks obtained by each student.
Constraints
1≤ N ≤10
1≤M≤10
Marks range from 0 to 100
Sample Input:
33
80 75 90
60 70 65
85 95 88
First line → number of students and subjects.
Sample Output:
Student 1 Total = 245
Student 2 Total = 195
Student 3 Total = 268
[Link] Statement
A shopkeeper sells 3 different products in his shop. For 3 days, he records:
How many items were available in stock
How many items were sold
The data is stored in two 2D arrays:
Stock array → items available
Sold array → items sold
Rows represent products, and columns represent days.
Write a program to calculate the remaining items after sales for each product on each day.
Formula:
Remaining = Stock – Sold
Display the remaining items in matrix format.
Constraints
 1≤products≤10
 1≤days≤7
 0≤stock[ i ][ j]≤1000
 0≤sold[ i ][ j]≤stock[ i][ j]
Sample Input:
Enter number of products and days:
33
Enter stock values:
50 40 30
60 50 45
70 65 60
Enter sold values:
10 5 8
15 10 5
20 10 15
Sample Output:
Remaining items:
40 35 22
45 40 40
50 55 45
[Link] Description

You are given a 1D array containing n distinct integers taken from the range 0 to n.
One number is missing from the array.

Write a program to find the missing number.

Input Format

First line: Integer n (size of array)

Second line: n space-separated integers


Output Format

Print the missing number

Sample Input
5
01245
Sample Output
3
[Link] Description
You are given an array representing the number of steps taken each day.
Find the number of days where the step count is strictly higher than the previous day.
Input Format
 First line: Integer n (number of days)
 Second line: n space-separated integers representing step counts
Output Format
 A single integer representing the number of days where steps increased compared
to the previous day
Constraints
 1 ≤ n ≤ 200
 0 ≤ steps[i] ≤ 100000
 For n = 1, output should be 0 (no previous day to compare)
Test Case 1
Input:
5
1000 2000 1500 1800 2500
Output:
3
Explanation:
2000 > 1000 ✔
1800 > 1500 ✔
2500 > 1800 ✔
Test Case 2
Input:
4
3000 3000 3000 3000
Output:
0
[Link] Book Arrangement System

A librarian maintains a list of book IDs. Every time a new book arrives, it is added to the list.
To keep the system efficient, the librarian wants the list to always remain sorted in ascending
order.

However, instead of sorting the entire list again, you must insert each new book into its
correct position using Insertion Sort logic.

Problem Statement

You are given an array of N book IDs.


Simulate the Insertion Sort process step-by-step and print the array after each iteration.

Input Format

First line: Integer N

Second line: N space-separated integers (book IDs)

Output Format

Print the array after each pass of insertion sort

Constraints

1 ≤ N ≤ 50

1 ≤ book ID ≤ 10^5

Do not use built-in sorting methods

Sample Input:
5
83529

Sample Output:
38529
35829
23589
23589
[Link] Price Tracker (First & Last Occurrence)

An e-commerce system stores product prices in sorted order.


Due to multiple sellers, the same price can appear multiple times.

When a user searches for a price, the system should return:

The first occurrence index

The last occurrence index

This helps in identifying the range of sellers offering that price.

Problem Statement

Given a sorted array of integers (prices) and a target value X,


find:

First occurrence of X

Last occurrence of X

If X is not found, return -1 -1.

Input Format

First line: Integer N

Second line: N sorted integers

Third line: Integer X

Output Format

Two integers: firstIndex lastIndex

Constraints

1 ≤ N ≤ 10^5

0 ≤ arr[i] ≤ 10^9

Must use Binary Search (O(log N))

Sample Input 1:
7
10 20 20 20 30 40 50
20

Sample Output 1:
13

Sample Input 2:
7
10 20 20 20 30 40 50
25

Sample Output 2:
-1 -1

You might also like