<jupyter_start><jupyter_text>2020년 3월 11일 수요일 HackerRank : Array - Minimum Swaps 2 문제 : https://www.hackerrank.com/challenges/minimum-swaps-2/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays 블로그 :https://somjang.tistory.com/entry/HackerRank-Array-Minimum-Swaps-2-Python  첫번째 시도<jupyter_code>#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the minimumSwaps function below.
def minimumSwaps(arr):
    sorted_arr = sorted(arr)
    answer = 0

    for i in range(len(arr)-1):
        min_num = min(arr[i+1:])
        if sorted_arr == arr:
            break
        if arr[i] > min_num:
            index = arr.index(min_num)
            temp = arr[i]
            arr[i] = arr[index]
            arr[index] = temp
            answer = answer + 1
    return answer<jupyter_output><empty_output><jupyter_text>---  두번째 시도<jupyter_code>#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the minimumSwaps function below.
def minimumSwaps(arr):
    answer = 0

    for i in range(len(arr)):
        while(arr[i] != i+1):
            temp = arr[i]
            arr[i] = arr[temp-1]
            arr[temp-1] = temp
            answer = answer + 1
    return answer<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11325115562403698, 'fraction_numerical': 0.01926040061633282, 'mean_word_length': 2.7435158501440924, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '319910', 'license': 'MIT', 'n_tokens_mistral': 492, 'n_tokens_neox': 489, 'n_words': 100, 'path': 'DAY 001 ~ 100/DAY034_[HackerRank] Array Minimum Swaps2 (Python).ipynb', 'repo_name': 'SOMJANG/CODINGTEST_PRACTICE', 'size': '1298'}