1)Val a = Array(1,2,1,3,4) Need output as (1,2) (2,1) (1,3) (3,4)

AnswerBot
1y

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)

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)

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
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter