All Submissions


Do you want a story?
No! Let's get straight to business.

You are given an array of N strings, You need to sort the array in lexicographical order. Only move allowed while sorting is you can only swap strings at adjacent positions.That means
You can swap -
1. String Ai with String Ai+1
2. String Ai with String Ai-1
You need to output the minimum number of moves it will take to sort the Array.

Input
An integer N(<=1000) denoting the size of the array.
N strings on every next line, where ith string denotes string Ai(length of each string<=10)

Output
An integer denoting the minimum number of moves.

Sample Input
5
Catelyn
Jon
Sansa
Winterfell
Arya

Sample Output
4

Explanation
It will take 4 moves to move Arya from 5th to 1st position.

Languages: AWK,Bash,Brain,C,C++,Java,C#,JavaScript,Pascal,Perl,PHP,Python,Python3,Ruby,Text

Time Limit: 1 Second(s)
Score: 50 Point(s)
Input File Limit: 50000 Bytes

Submit

Login to post clarification.

aditya:
Q. troller('safeCtrl', ['$scope', function ($scope) { > > var firstnames = ['Laurent', 'Blandine', 'Olivier', 'Max']; > var lastnames = ['Renard', 'Faivre', 'Frere', 'Eponge']; > var dates = ['1987-05-21', '1987-04-25', '1955-08-27', '1966-06-06']; > var id = 1; > > function generateRandomItem(id) { > > var firstname = firstnames[Math.floor(Math.random() * 3)]; > var lastname = lastnames[Math.floor(Math.random() * 3)]; > var birthdate = dates[Math.floor(Math.random() * 3)]; > var balance = Math.floor(Math.random() * 2000); > > return { > id: id, > firstName: firstname, > lastName: lastname, > birthDate: new Date(birthdate), > balance: balance > } > } > > $scope.rowCollection = []; > > for (id; id < 5; id++) { > $scope.rowCollection.push(generateRandomItem(id)); > } > > //add to the real data holder > $scope.addRandomItem = function addRandomItem() { > $scope.rowCollection.push(generateRandomItem(id)); > id++; > }; > > /remove to the real data holder > $scope.removeItem = function removeItem(row) { > var index = $scope.rowCollection.indexOf(row); > if (index !== -1) { > $scope.rowCollection.splice(index, 1); > } > } > }]);

Contest

Mode Judge

Passive

Online

Overall Rankings