Valid Pair - CodeChef Solution in Java | AskTheCode

Updated: Apr 12

CodeChef April Long Challenge Solution| Valid Pair (SOCKS1) solution in Java | AskTheCode


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.


The first and only line of the input contains three space-separated integers A, B and C.


Print a single line containing the string "YES" if it is possible for Chef to wear two socks with the same colour or "NO" if it is impossible (without quotes).

You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

Example Input 1:

5 4 3

Example Output 1:



Since there are no two socks with the same colour, Chef cannot wear a pair of socks with the same colour.

Example Input 1:

5 5 5

Example Output 1:



Since all three socks have the same colour, Chef can wear a pair of socks with the same colour.


In Java

/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
 public static void main(String[] args) {
        Scanner input = new Scanner(;
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();

    public static String solve(int a, int b, int c) {
        if (a == b || a == c || b == c) {
            return "Yes";
        } else {
            return "No";

In C++

#include <iostream>
using namespace std;

int main() {
	int a[3],k=0;
	for(int i=0;i<2;i++)
	    if (a[i]==a[i+1])
	if (k==0)
	return 0;
872 views0 comments

Recent Posts

See All

Golf CodeChef Solution in Java - AskTheCode

CodeChef May Long Challenge Solution | Golf (LKDNGOLF) solution | AskTheCode Golf (LKDNGOLF) solution Problem: It's a lockdown. You’re bored in your house and are playing golf in the hallway. The hall

Solubility - CodeChef Solution in Java and C++| AskTheCode

CodeChef May Long Challenge Solution | Solubility (SOLBLTY) solution | AskTheCode Solubility (SOLBLTY) solution Problem: Suppose for a unit rise in temperature, the solubility of sugar in water increa

Valid Paths CodeChef Solution in C++ | AskTheCode

CodeChef May Long Challenge Solution | Valid Paths (VPATH) solution | AskTheCode Valid Paths (VPATH) CodeChef solution Problem: You are given a tree with N nodes numbered from 1 to N. A set S of nodes