Explanation: Find the index of the element in the array and then take the index value to find it's index. Eg: Array 2 3 1 Index of 1 is 3 Find index of 3 which is 2 Add to new array Index of 2 is 1 Find index of 1 which is 3 Add to new array Repeat Steps def permutationEquation ( p ): new = [] for i in range ( 1 , len ( p ) + 1 ): new . append ( p . index ( p . index ( i ) + 1 ) + 1 ) return new
David has several containers, each with a number of balls in it. He has just enough containers to sort each type of ball he has into its own container. David wants to sort the balls using his sort method. As an example, David has containers and different types of balls, both of which are numbered from to . The distribution of ball types per container are described by an matrix of integers, . For example, consider the following diagram for : In a single operation, David can swap two balls located in different containers. The diagram below depicts a single swap operation: David wants to perform some number of swap operations such that: Each container contains only balls of the same type. No two balls of the same type are located in different containers. You must perform queries where each query is in the form of a matrix, . For each query, print Possible on a new line if Davi...
We define the distance between two array values as the number of indices between the two values. Given , find the minimum distance between any pair of equal elements in the array. If no such value exists, print . For example, if , there are two matching pairs of values: . The indices of the 's are and , so their distance is . The indices of the 's are and , so their distance is . Function Description Complete the minimumDistances function in the editor below. It should return the minimum distance between any two matching elements. minimumDistances has the following parameter(s): a : an array of integers Input Format The first line contains an integer , the size of array . The second line contains space-separated integers . Constraints Output Format Print a single integer denoting the minimum in . If no such value exists, print . S...
Comments
Post a Comment