Hello coders, today we are going to solve Final Population Codechef Solution whose Problem Code is POPULATION.
As you already know that this site does not contain only the Codefchef solutions here, you can also find the solution for other programming problems. I.e. Leetcode, C programs, C++ Programs Solutions, Python Programs, Web Technology, Data Structures, RDBMS Programs and Java Programs Solutions.

Problem
There were initially XX million people in a town, out of which YY million people left the town and ZZ million people immigrated to this town.
Determine the final population of town in millions.
Input Format
- The first line of input will contain a single integer TT, denoting the number of test cases.
- The first and only line of each test case consists of three integers XX, YY and ZZ.
Output Format
For each test case, output the final population of the town in millions.
Constraints
- 1≤T≤100
- 1≤X,Y,Z≤10
- Y≤X
Sample 1:
Input
4
3 1 2
2 2 2
4 1 8
10 1 10
Output
4
2
11
19
LinkedIn Skill Assessment Answers
Coursera Quiz Answers
Explanation:
Test case 11: The initial population of the town was 33 million, out of which 11 million people left and 22 million people entered the town. So, final population = 3 – 1 + 2 = 4=3−1+2=4 million.
Test case 22: The initial population of the town was 22 million, out of which 22 million left and 22 million immigrated. The final population is thus 2+2-2 = 22+2−2=2 million.
Final Population Codechef Solution 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 Scanner sc=new Scanner(System.in); public static void main (String[] args) throws java.lang.Exception { int t,n; t=sc.nextInt(); while(t-- >0){ n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=sc.nextInt(); Arrays.sort(arr); for(int i=0;i<n;i++) System.out.print(arr[i]+" "); System.out.println(); } } }
Final Population Codechef Solution in CPP
#include <iostream> #include<bits/stdc++.h> using namespace std; int main() { // your code goes here int t; cin>>t; while(t--) { int n; cin>>n; int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n); for(int i=0;i<n;i++) { cout<<a[i]<<" "; } cout<<endl; } return 0; }
Final Population Codechef Solution in Python
for i in range(int(input())): n = input() lst = list(map(int,input().split())) lst.sort() for i in lst: print(i,end=" ") print()
Disclaimer: The above Problem (Final Population ) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.
Finally, we are now, in the end, I just want to conclude some important message for you
Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.
Please share our posts on social media platforms and also suggest to your friends to Join Our Groups. Don’t forget to subscribe.