Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Given a list A of elements of length N , ranging from 1 to N . All elements may not be present in the

1) Given a listAof elements of lengthN, ranging from1 to N. All elements may not be present in the array. If the element is not present then there will be -1 present in the array. Rearrange the array such thatA[i] = iand if i is not present display -1 at that place.

Input Format:

The first line contains n numbers with each number separated by a space.

Output Format:

Print the elements of the list after the modification.

Example:

Input:

-1 -1 6 1 9 3 2 -1 4 -1

Output:

-1 1 2 3 4 -1 6 -1 -1 9

Explanation:

The modified list contains elements such that A[i] = i.

Test cases

input

3 1 4 2 5 0

Output

0 1 2 3 4 5

Input

2 1 3 4 -1

Output

-1 1 2 3 4

Input

4 7 -1 9 -1 5 3 -1 -1 -1

Output

-1 -1 -1 3 4 5 -1 7 -1 9

NOTE:

1.Input should be accepted from the user as many as he enter. User donotknow how many digits he is going to enter.

2. All the test cases should be satisfied

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

6. Is the optimal level of pollution zero? Why or why not?

Answered: 1 week ago