Home /
Expert Answers /
Computer Science /
weight-lifting-equipment-coding-challenge-please-use-js-or-ruby-language-nbsp-1-code-question-1-pa281
(Solved): Weight lifting equipment coding challenge . please use JS or Ruby language 1. Code Question 1 ...
Weight lifting equipment coding challenge . please use JS or Ruby language
1. Code Question 1 Imagine you are shopping on Amazon.com for some good weight lifting equipment. The equipment you want has plates of many different weights that you can combine to lift. The listing on Amazon gives you an array, plates, that consists of \( n \) different weighted plates, in kilograms. There are no two plates with the same weight. The element plates[i] denotes the weight of the \( \mu^{\text {th }} \) plate from the top of the stack. You consider weight lifting equipment to be good if the plate at the top is the lightest, and the plate at the bottom is the heaviest. More formally, the equipment with array plates will be called good weight lifting equipment if it satisfies the following conditions (assuming the index of the array starts from 1): - plates[1]
Given that - All items of array are unique. We can only swap adjacent plates We need to - Sort the list in ascending order Count the number of swaps This is nothing but a glorified BubbleSort Problem. We need to simply apply bubble sort and count the