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]))

Select
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
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits