Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

Codechef Max minus Min problem solution

YASH PAL, 31 July 2024

In this Codechef Max minus Min problem solution Chef is given 33 integers A, B,A,B, and CC such that A lt B lt CA<B<C.

Chef needs to find the value of max(A, B, C) – min(A, B, C)max(A,B,C)−min(A,B,C).

Here max(A, B, C)max(A,B,C) denotes the maximum value among A, B, CA,B,C while min(A, B, C)min(A,B,C) denotes the minimum value among A, B, CA,B,C.

Codechef Max minus Min problem solution

Problem solution in Python programming.

# cook your dish here
t=int(input())
while t :
    lst=list(map(int,input().split()))
    print(max(lst)-min(lst))
    t=t-1

Problem solution in Java programming.

/* package codechef; // don't place package name! */

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) 
	{
		Scanner sc = new Scanner(System.in);
		int T=sc.nextInt();
		for (int Z=1;Z<=T;Z++){
		    int A=sc.nextInt();
		    int B=sc.nextInt();
		    int C=sc.nextInt();
		    int array[]=new int[3];
		    array[0]=A;
		    array[1]=B;
		    array[2]=C;
		    for (int i=0;i<array.length;i++){
		        for(int j=i+1;j<array.length;j++){
		            if(array[i]>array[j]){
		                int temp=array[i];
		                array[i]=array[j];
		                array[j]=temp;
		            }
		        }
		    }
		  System.out.println(array[array.length-1]-array[0]);
		}
	}
}

Problem solution in C++ programming.

#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	for(int i=0;i<t;i++)
	{
	    int x,y,z;
	    cin>>x>>y>>z;
	    int min;
	    int max;
	    if(x>y && x>z)
	    {
	        max=x;
	    }
	    else if(y>x && y>z)
	    {
	        max=y;
	    }
	    else
	    {
	        max=z;
	    }
	    if(x<y && x<z)
	    {
	        min=x;
	    }
	    else if(y<x && y<z)
	    {
	        min=y;
	    }
	    else
	    {
	        min=z;
	    }
	    cout<<max-min<<endl;
	}
	return 0;
}

Problem solution in C programming.

#include <stdio.h>

int main(void) {
	// your code goes here
	int t;
	scanf("%d",&t);
	while(t--)
	{
	    int x,y,z;
	    scanf("%d %d %d",&x,&y,&z);
	    printf("%dn",z-x);
	}
	return 0;
}
Codechef Solutions coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes