Given an array a = Array(1,2,1,3,4), how would you output the following pairs: (1,2), (2,1), (1,3), (3,4)?

AnswerBot
2y
Print pairs of adjacent elements in an array
Loop through the array and print each pair of adjacent elements
Use a for loop and access the elements using their indices
Example: for i in 0 until a.length-...read more
Tareni sankar swain
1y
(1,2)
(2,1)
(1,3)
(3,4)

Dhanraj
2mo
12
Abhishek Jha
1y
a = [1, 2, 1, 3, 4] pairs = [(a[i], a[i+1]) for i in range(len(a) - 1)] for pair in pairs: print(pair)

Dhanraj
2mo
1
Anonymous
1y
def sublists(lst): n = len(lst) sublists = [] for start in range(n): for end in range(start + 1, n + 1): sublists.append(lst[start:end]) return sublists original_list = [1, 2, 1, 3, 4] sublists_nested...read more
AMIR AKHTAR
1y
Post in ChatGPT , you will get your answer
himanshu kumar
1y
a = [1,2,1,3,4] # (1,2) (2,1) (1,3) (3,4) for i in range(len(a)-1): print((a[i], a[i+1]))
Add answer anonymously...
Tech Mahindra Senior Software Engineer interview questions & answers
A Senior Software Engineer was asked 1w agoQ. How do you pass data from children to parent in React?
A Senior Software Engineer was asked 1w agoQ. How do you manage state in a React application?
A Senior Software Engineer was asked 1w agoQ. What are hooks used for, and why are they used in React?
Popular interview questions of Senior Software Engineer
A Senior Software Engineer was asked 1w agoQ1. How do you pass data from children to parent in React?
A Senior Software Engineer was asked 1w agoQ2. How do you manage state in a React application?
A Senior Software Engineer was asked 1w agoQ3. What are hooks used for, and why are they used in React?
>
Tech Mahindra Senior Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

