Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • 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
Programmingoneonone

HackerEarth Soft Sort problem solution

YASH PAL, 31 July 2024
In this HackerEarth Soft Soft problem solution Let us define an easy Sorting Algorithm called SoftSort. SoftSort Sorting algorithm involves the use of IF and ELSE decision statements only. For example :
To sort two numbers a and b. SoftSort Algorithm’s Code is given below.
void print(int a,int b){
    printf( “%d %dn”,a,b);
}
void sort( int a, int b){
    if( b < a )
        print( b, a );
     else
        print( a, b );
}
To sort three numbers a , b and c . Source Code is given below.
  void print( int a, int b, int c ) {
        printf( “%d %d %dn”, a, b, c );
}
void sort( int a, int b, int c ) {
        if( a < b )
            if( a < c )
                if( b < c )
                    print( a, b, c );
                else
                    print( a, c, b );
            else
                print( c, a, b );
        else
            if( b < c )
                if( a < c )
                    print( b, a, c );
                else
                    print( b, c, a );
            else
                print( c, b, a );
    }
ANI is fascinated with the SoftSort Algorithm and decided to ask an interesting question to KUKU.
What could be the length of source code to sort n numbers using SoftSort Algorithm?
HackerEarth Soft Sort problem solution

HackerEarth Soft Sort problem solution.

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ft first
#define sd second
#define VI vector<int>
#define VLL vector<long long int>
#define PII pair<int,int>
#define pb push_back
#define rsz(v,n) v.resize(n)
// input and output
#define scan(x) scanf("%d",&x)
#define scanll(x) scanf("%lld",&x)
#define ll long long int
#define rep(i,x,y) for(i=x;i<y;i++)
#define print(x) printf("%dn",x)
#define printll(x) printf("%lldn",x)
#define all(v) v.begin(),v.end()
#define ms(v) memset(v,0,sizeof(v))
#define FOR(i,a,b) for(i=a;i<b;i++)
#define PIE 3.14159265358979323846264338327950
#ifdef ONLINE_JUDGE
inline void inp( int &n )
{
n=0;
int ch=getchar_unlocked();int sign=1;
while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getchar_unlocked();}

while( ch >= '0' && ch <= '9' )
n = (n<<3)+(n<<1) + ch-'0', ch=getchar_unlocked();
n=n*sign;
}
#else
inline void inp(int &n){
cin>>n;
}
#endif

ll fact[1000001];
void pre_process()
{
fact[0]=1;
for(int i=1;i<=1000000;i++)
{
fact[i]=(fact[i-1]*i)%MOD;
}
}
int main()
{
int n,t;
pre_process();
inp(t);
assert(1<=t&&t<=100000);
while(t--)
{
int n;
inp(n);
assert(1<=n&&n<=1000000);
ll ans=((3*fact[n])%MOD+3)%MOD;
printll(ans);
}
return 0;
}

Second solution

 #include <cstdlib>
#include <stdio.h>
#include <cstring>
#include <complex>
#include <vector>
#include <cmath>
#include <ctime>
#include <iostream>
#include <numeric>
#include <algorithm>
#include <map>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <iomanip>
#include <locale>
#include <sstream>
#include <string>
#define FOR(i,n) for(i=0;i<n;i++)
#define FORI(i,a,n) for(i=a;i<n;i++)
#define FORC(it,C) for(it=C.begin();it!=C.end();it++)
#define scanI(x) scanf("%d",&x)
#define scanD(x) scanf("%lf",&x)
#define print(x) printf("%dn",x)
#define MAX 2000004
#define MOD 1000000007
typedef long long ll;

using namespace std;

ll fact[MAX],ifact[MAX];


ll power(ll n,int m)
{
if(m==0) return 1;
ll x=power(n,m/2);
if(m%2==0)
return (x*x)%MOD;
else
return (((x*x)%MOD)*n)%MOD;
}

void preProcess()
{
fact[0]=1;
ifact[0]=1;
int i;
for(i=1;i<MAX;i++)
{
fact[i]=fact[i-1]*i;
fact[i]%=MOD;
}
ifact[2000000] = power(fact[2000000],MOD-2);
for(i=2000000;i>1;i--)
ifact[i-1] = ifact[i]*i%MOD;
}

ll comb(int a)
{
return (((fact[a]*3)%MOD+3)%MOD)%MOD;
}



int main() {
std::ios_base::sync_with_stdio(false);
int t;
cin >> t;
ll ans;
preProcess();
while(t--){
ll n;
cin >> n;
ans=comb(n);
ans%=MOD;
printf("%lldn",ans);
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes