5 kyu

The Sum and The Rest of Certain Pairs of Numbers have to be Perfect Squares (more Challenging)

93 of 190raulbc777

Description:

This the second part part of the kata:

https://www.codewars.com/kata/the-sum-and-the-rest-of-certain-pairs-of-numbers-have-to-be-perfect-squares

In this part we will have to create a faster algorithm because the tests will be more challenging.

The function n_closestPairs_tonum(), (Javascript: nClosestPairsToNum()), will accept two arguments, upper_limit and k.

The function should return the k largest pair of numbers [m, n] and the closest to upper_limit. Expressing it in code:

n_closestPairs_tonum(upper_limit, k) #-> [[m1, n1], [m2, n2], ...., [mk, nk]]
nClosestPairsToNum(upperLimit, k) //-> [[m1, n1], [m2, n2], ...., [mk, nk]]

Such that:

upper_limit >= m1 >= m2 >= ....>= mk > 0

Examples:

upper_limit = 1000; k = 4
n_closestPairs_tonum(upper_limit, k) == [[997, 372], [986, 950], [986, 310], [985, 864]]

upper_limit = 10000; k = 8
n_closestPairs_tonum(upper_limit, k) == [[9997, 8772], [9997, 2772], [9992, 6392], [9986, 5890], [9985, 7176], [9985, 4656], [9981, 9900], [9973, 9348]]

Features of the tests:

1000 ≤ upper_limit ≤ 200000
2 ≤ k ≤ 20

Enjoy it!

Algorithms
Mathematics
Data Structures

Stats:

CreatedAug 10, 2016
PublishedAug 10, 2016
Warriors Trained831
Total Skips97
Total Code Submissions829
Total Times Completed190
Python Completions93
Ruby Completions20
JavaScript Completions52
C++ Completions42
Total Stars17
% of votes with a positive feedback rating87% of 47
Total "Very Satisfied" Votes36
Total "Somewhat Satisfied" Votes10
Total "Not Satisfied" Votes1
Total Rank Assessments4
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • raulbc777 Avatar
  • smile67 Avatar
  • lechevalier Avatar
  • Voile Avatar
  • hobovsky Avatar
  • Just4FunCoder Avatar
  • 66  Avatar
Ad