Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Lists #57

Open
ndrohith09 opened this issue Oct 20, 2022 · 1 comment
Open

Lists #57

ndrohith09 opened this issue Oct 20, 2022 · 1 comment
Assignees
Labels
easy question Further information is requested

Comments

@ndrohith09
Copy link
Member

Consider a list (list = []). You can perform the following commands:

  1. insert i e: Insert integer e at position i .
  2. print: Print the list.
  3. remove e: Delete the first occurrence of integer e.
  4. append e: Insert integer e at the end of the list.
  5. sort: Sort the list.
  6. pop: Pop the last element from the list.
  7. reverse: Reverse the list.

Initialize your list and read in the value of n followed by n lines of commands where each command will be of the 7 types listed above. Iterate through each command in order and perform the corresponding operation on your list.

Example

N = 4 
append 1
append 2 
insert 3 1 
print 
  • append 1 : Append 1 to list , arr = []
  • append 2 : Append 2 to the list , arr = [1 , 2]
  • insert 3 1: insert 3 at index 1 , arr = [1 , 3 ,2]
  • print : Print the array
  • output
[1 , 3 , 2]

Input Format

The first line contains an integer, n, denoting the number of commands.
Each line i of the n subsequent lines contains one of the commands described above.

Constraints

  • The elements added to the list must be integers.

Output Format

For each command of type print, print the list on a new line.

Sample Input 0

12
insert 0 5
insert 1 10
insert 0 6
print
remove 6
append 9
append 1
sort
print
pop
reverse
print

Sample Output 0

[6, 5, 10]
[1, 5, 9, 10]
[9, 5, 1]
@ndrohith09 ndrohith09 added question Further information is requested easy labels Oct 20, 2022
@riyatomar9
Copy link
Contributor

I want to solve it using python

riyatomar9 added a commit to riyatomar9/hacktoberfest that referenced this issue Oct 20, 2022
@riyatomar9 riyatomar9 mentioned this issue Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
easy question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants