J88Y7 - Editorial

#PROBLEM LINK:

Problem

Author:Kunal Raje

Tester:Kunal Raje

Editorialist: Harsh Savergaonkar

#DIFFICULTY:

CAKEWALK

#PREREQUISITES:

Simple Math

#PROBLEM:

To accept a list of numbers and sort it according to given criteria which were:

  • Square numbers must come first and should be sorted
  • Non-Square numbers are placed after and should also be sorted

#QUICK EXPLANATION:

This problem is rather simple and self explanatory and the requirements are that we must

  • Find the square terms
  • Sort them
  • Sort the remaining numbers and place them after the sorted list of squares
  • Print the list

#EXPLANATION:

First, we need to accept the input and store it according to the necessity. We then need to identify the square terms in the list, hence, the best way to do this is with a for loop, which will check each input number and see if it’s square root is a natural number (that way we can tell if it is a perfect square or not)

Next, the squares need to be brought in the beginning of the list.

We can also check if each number is greater than its preceding number in each of the iterations of the same for loop.

#ALTERNATIVE SOLUTION:

The numbers can first be sorted in ascending order and then the perfect squares can be found and put befor ethe list as and when found, automatically going in correct order

#AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.

Tester’s solution can be found here.

#RELATED PROBLEMS: