Archives

The Pads HackerRank Advanced SQL Questions [Solved]

Stuck with Advanced Select problem in SQL?
https://www.hackerrank.com/challenges/the-pads/problem

NO WORRIES! HERE IS THE SOLUTION!

SELECT CONCAT(NAME,'(',SUBSTR(OCCUPATION,1,1),')') AS N
 FROM OCCUPATIONS
 ORDER BY N;
 SELECT CONCAT('There are a total of ',COUNT(OCCUPATION),' ',LOWER(OCCUPATION),'s.')
 FROM OCCUPATIONS
 GROUP BY OCCUPATION
 ORDER BY COUNT(OCCUPATION), OCCUPATION;

Read more...

HackerRank Minimum Swaps 2 Problem [Solved]

https://www.hackerrank.com/challenges/minimum-swaps-2/problem No worries! It is as simple as HELL!!

    static int minimumSwaps(int[] arr) {
            int swapCount = 0;
            for (int index = 0; index < arr.Length - 1; index++)
            {
                if (arr[index] != (index + 1))
                {
                    for (int swapIndex = index + 1; swapIndex < arr.Length; swapIndex++)
                    {
                        if (arr[swapIndex] == (index + 1))
                        {
                            int aux = arr[swapIndex];
                            arr[swapIndex] = arr[index];
                            arr[index] = aux;
                            swapCount++;
                            break;
                        }
                    }
                }
            }
            return swapCount;   
}

Read more...

HackerRank Solutions Grading Students Problem [SOLVED]

It is as simple as HELL!!

https://www.hackerrank.com/challenges/grading/problem

SO EASY!!

    public static List<int> gradingStudents(List<int> grades)
    {
         for (int i = 0; i < grades.Count; i++)
        {
            var item = grades[i];
            if (item >= 38)
            {
                var diff = 5 - (item % 5);
                if (diff < 3)
                    grades[i] = item + diff;
            }
        }
      return grades;
    }

Read more...