Valid Pair (SOCKS1) Solution — Codechef April Long Challenge

Anubhav Mishra
2 min readApr 12, 2021

--

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.

Input

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

Output

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

Constraints

  • 1≤A,B,C≤10

Subtasks

Subtask #1 (100 points): original constraints

Example Input 1

5 4 3

Example Output 1

NO

Explanation

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

Example Input 2

5 5 5

Example Output 2

YES

Explanation

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

Code (Solution)

The code has been implemented in Java

import java.util.*;import java.lang.*;import java.io.*;/* Name of the class has to be "Main" only if the class is public. */class Codechef{public static void main (String[] args) throws java.lang.Exception{// your code goes hereScanner sc = new Scanner(System.in);int a = sc.nextInt();int b = sc.nextInt();int c = sc.nextInt();if((a==b) || (b==c) || (a==c)){System.out.println("YES");}else{System.out.println("NO");}}}

Hope you would have liked the article. Please give 50 claps to this article and follow me for more future programming related blogs.

References

https://www.codechef.com/APRIL21C/problems/SOCKS1

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Anubhav Mishra
Anubhav Mishra

Written by Anubhav Mishra

Software Engineer , Having my degree B.Tech in Information Technology from BVCOE, New Delhi. Love new Technologies. Electronic Dance Music is love.

No responses yet

Write a response