Created
February 14, 2022 15:02
-
-
Save micedreams/2777751fc28d4e192571cd4ecf0fd045 to your computer and use it in GitHub Desktop.
fineSwap screening test example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
int resultFindNthSmallest; | |
resultFindNthSmallest = findNthSmallest([6, 2, 9, 1], 2); | |
print("findNthSmallest([6, 2, 9, 1], 2) =$resultFindNthSmallest"); | |
resultFindNthSmallest = | |
findNthSmallest([57, 3, 0, -5, 2, 67, 32, 9, 1, 2], 5); | |
print( | |
"findNthSmallest([57, 3, 0, -5, 2, 67, 32, 9, 1, 2], 5) = $resultFindNthSmallest"); | |
} | |
findNthSmallest(List<int> integers,int nth){ | |
assert(integers.length >= nth); | |
List<int> resultArray =[]; | |
List<int> mainArray =integers; | |
var i=0; | |
while(i<nth){ | |
int small = smallest(mainArray); | |
resultArray.add(small); | |
mainArray.remove(small); | |
i++; | |
} | |
return resultArray.last; | |
} | |
int smallest(List<int> integers) { | |
int result = integers[0]; | |
for(var i=0;i<integers.length;i++){ | |
if (integers[i] < result) result = integers[i]; | |
} | |
return result; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment