ArrayList are dynamic size arrays. Try this problem using ArrayList.

Given a ArrayList of **n** elements and a integer **q** defining the query number(which will be either 1 or 2) :

**Query 1** includes two integers **p** and **r**. Which means add a value r at and index p in the ArrayList and print the whole updated ArrayList.

**Query 2** includes one integer **p**. In this query print the index at which the value p is last found in the ArrayList. If the value p is not found int he ArrayList then print "**-1**".

**NOTE: Assume 0 based indexing**

**Input:**

First line of input file contains an integer T, denoting the number of test cases. Then T test case follow. First line of each test case contains two integer n and q(space separated). Second Line of each test case consists of n spaced integers. Third line consists of 2 integers if the value of q is 1 otherwise consists of a single integer.

**Output:**

For each test case, print required output.

**Constraints:**

1<=T<=10

1<=n<=10^{4}

1<=element<=10^{3}

**Example:**

**Input:**

2

5 1

1 4 5 9 3

2 6

4 2

1 9 2 4

4

**Output:**

1 4 6 5 9 3

3

Author: saksham0751

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

VISHESHA SADU | 27 |

ghanshyam648 | 25 |

Biswajit3 | 21 |

karthik_kasaragadda | 20 |

tanya_sharma | 18 |

KshatriyaYash | 1066 |

nikhil_sojan | 978 |

lonecoder | 935 |

mazumderrohit8 | 864 |

SumitSingh27 | 832 |

blackshadows | 5327 |

Ibrahim Nash | 5215 |

akhayrutdinov | 5111 |

mb1973 | 4468 |

Quandray | 4444 |

Login to report an issue on this page.