Find the start and end index of unsorted subarray such that sorting this subarray can sort all the array.
Input: [2,6,4,8,10,9,15]
Output: 1 5
#Starting Index is 1 and Ending index is 5
def shortsub(arr): N=len(arr) L,arr1 = [],arr[:] arr1.sort() for i in range(N): if(arr[i]!=arr1[i]): L.append(i) if bool(L): return [L[0],L[-1]] else: return 0 A=list(map(int,input("Array: ").split(" "))) L=shortsub(A) print(L[0],L[1]) if L!=0 else print(None)
INPUT_1:
Array: 2 6 4 8 10 9 15
OUTPUT:
1 5
INPUT_2:
Array: 1 2 3 4
OUTPUT:
None
INPUT_3:
Array: 1
OUTPUT:
None
INPUT_4:
Array: 10 12 20 30 25 40 32 31 35 50 60
OUTPUT:
3 8
INPUT_5:
Array: 0 1 15 25 6 7 30 40 50
OUTPUT:
2 5
ILLUSTRATION
Morae Q!
- Conversion of days into year, weeks and days.
- Find if the number is a perfect number or not.
- Compute conversion of Binary to Octal.
- Return the sum of digits in a number.
- Find if a word exists or not in a sentence.
- Convert Numbers into Words.
- Read a word if it consists only of the letters known.
- Check if the string is a dynamic string or not.
- Convert all Uppercase letters to Lowercase and vice-versa.
- Change the string such that there are no matching adjacent characters.
- Find the number of sub-strings which start and end both in 1.
- Find the start and end index of unsorted sub-array.
- Find the maximum number of pairs that can be formed.
- Figure out the number of bubbly words present.
- Check if a string is lapindrome or not even with a middle character.
- Seating layout in a triangular shaped class according to the number of rows.
- Find and Sort a sub-array which makes whole array sorted.
- Seating layout according to the number of rows.
- Find the final states of the bulbs.
- Check if reversing sub array makes the array sorted.