We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Sorting
- Lily's Homework
- Discussions
Lily's Homework
Lily's Homework
Sort by
recency
|
273 Discussions
|
Please Login in order to post a comment
import java.io.; import java.util.; import java.util.stream.*;
class Result {
}
public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
}
simple c++ code with function
int getswaps(unordered_map& d) { int swap = 0; for (auto& pair : d) { int x = pair.first; int y = pair.second; while (x != y) { swap++; d[x] = d[y]; d[y] = y; y = d[x]; } } return swap; } int lilysHomework(vector arr) { vector arrs = arr; sort(arrs.begin(), arrs.end()); unordered_map d1, d2;
}
javascript
Sort the Array Track Cycles Count Swaps = (cycle length - 1) I run the test array [3,4,2,5,1] ->output 4, but the expected answer is 2,why?
def lilysHomework(arr): # Write your code here # Create a list of tuples where each tuple is (element, original_index) n = len(arr) arr_with_indices = [(arr[i], i) for i in range(n)]