Infosys OA | Minimum Adjacent Swaps to Group Pairs | OA | 2023

Infosys · Question · Posted Apr 2026

Problem Statement You are given an array A of size N. It is guaranteed that N is even and that each distinct value appears in array A exactly twice. In one operation, you can choose two adjacent numbers in A and swap them. Your task is to find the minimum number of operations needed such that each pair of equal numbers becomes adjacent in the array. Input Format The first line contains an integer N, denoting the number of elements ...

The full answer & interview discussion are available to premium members.

Log in Create a free account