Hydroid
1 min readApr 6, 2021

--

CodeChef April’21 Long Challenge Solution (Div 3) — Valid Pair

Problem Statement :

Chef has three socks in his drawer. Each sock has one of 10 possible colours, which are represented by integers between 1 and 10. Specifically, the colours of the socks are A, B, and C.

Chef has to wear two socks which have the same colour. Help Chef find out if that is possible or not.

Problem Link: Valid Pair

Solution:

import java.util.*;
import java.lang.*;
import java.io.*;
class CodeChef {public static String solve(int[] arr, int sizeOfArray) {

if (arr[0] == arr[1])
return "YES";
else if (arr[0] == arr[2])
return "YES";
else if (arr[1] == arr[2])
return "YES";
else
return "NO";
}

// Driver Method
public static void main (String[] args) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int[] arr = new int[3];

// to read multiple integers line
String line = br.readLine();
String[] strs = line.trim().split("\\s+");

for (int i = 0; i < arr.length; i++) {
arr[i] = Integer.parseInt(strs[i]);
}
System.out.println(solve(arr, arr.length));
}

}

--

--

Hydroid

Currently working as a Full Stack Developer in India