Skip to content

Instantly share code, notes, and snippets.

@micedreams
Created February 14, 2022 15:02
Show Gist options
  • Save micedreams/2777751fc28d4e192571cd4ecf0fd045 to your computer and use it in GitHub Desktop.
Save micedreams/2777751fc28d4e192571cd4ecf0fd045 to your computer and use it in GitHub Desktop.
fineSwap screening test example 1
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