|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 10, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "name": "stdout", |
| 10 | + "output_type": "stream", |
| 11 | + "text": [ |
| 12 | + "2\n", |
| 13 | + "5\n", |
| 14 | + "4 2 1 5 3\n", |
| 15 | + "2 1 -1 3 -1\n", |
| 16 | + "6\n", |
| 17 | + "5 6 2 3 1 7\n", |
| 18 | + "-1 2 -1 1 -1 -1\n" |
| 19 | + ] |
| 20 | + } |
| 21 | + ], |
| 22 | + "source": [ |
| 23 | + "#immediate smaller element -----> AMAZON\n", |
| 24 | + "#marks = 1, difficulty = Basic\n", |
| 25 | + "'''\n", |
| 26 | + "Given an integer array of size N. For each element in the array, check whether the right adjacent element (on the next immediate position) of the array is smaller. If next element is smaller, print that element. If not, then print -1.\n", |
| 27 | + "\n", |
| 28 | + "Input:\n", |
| 29 | + "The first line of input contains an integer T denoting the number of test cases. T testcases follow. Each testcase contains 2 lines of input:\n", |
| 30 | + "The first line contains an integer N, where N is the size of array.\n", |
| 31 | + "The second line contains N integers(elements of the array) sperated with spaces.\n", |
| 32 | + "\n", |
| 33 | + "Output:\n", |
| 34 | + "For each test case, print the next immediate smaller elements for each element in the array.\n", |
| 35 | + "\n", |
| 36 | + "Constraints:\n", |
| 37 | + "1 ≤ T ≤ 200\n", |
| 38 | + "1 ≤ N ≤ 107\n", |
| 39 | + "1 ≤ arr[i] ≤ 1000\n", |
| 40 | + "\n", |
| 41 | + "Example:\n", |
| 42 | + "Input\n", |
| 43 | + "2\n", |
| 44 | + "5\n", |
| 45 | + "4 2 1 5 3\n", |
| 46 | + "6\n", |
| 47 | + "5 6 2 3 1 7\n", |
| 48 | + "\n", |
| 49 | + "Output\n", |
| 50 | + "2 1 -1 3 -1\n", |
| 51 | + "-1 2 -1 1 -1 -1\n", |
| 52 | + "\n", |
| 53 | + "Explanation:\n", |
| 54 | + "Testcase 1: Array elements are 4, 2, 1, 5, 3. Next to 4 is 2 which is smaller, so we print 2. Next of 2 is 1 which is smaller, so we print 1. Next of 1 is 5 which is greater, so we print -1. Next of 5 is 3 which is smaller so we print 3. Note that for last element, output is always going to be -1 because there is no element on right.\n", |
| 55 | + "'''\n", |
| 56 | + "n=int(input())\n", |
| 57 | + "for i in range(n):\n", |
| 58 | + " m=int(input())\n", |
| 59 | + " a=list(map(int,input().split()))\n", |
| 60 | + " for j in range(m-1):\n", |
| 61 | + " if j<m-1:\n", |
| 62 | + " if a[j]>a[j+1]:\n", |
| 63 | + " print(a[j+1],end=' ')\n", |
| 64 | + " else:\n", |
| 65 | + " print(-1,end=' ')\n", |
| 66 | + " else:\n", |
| 67 | + " print(-1)" |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + "cell_type": "code", |
| 72 | + "execution_count": 2, |
| 73 | + "metadata": {}, |
| 74 | + "outputs": [ |
| 75 | + { |
| 76 | + "name": "stdout", |
| 77 | + "output_type": "stream", |
| 78 | + "text": [ |
| 79 | + "2\n", |
| 80 | + "5\n", |
| 81 | + "1 2 3 4 5\n", |
| 82 | + "2\n", |
| 83 | + "3 4 5 1 2 \n", |
| 84 | + "1\n", |
| 85 | + "5\n", |
| 86 | + "1\n", |
| 87 | + "5 \n" |
| 88 | + ] |
| 89 | + } |
| 90 | + ], |
| 91 | + "source": [ |
| 92 | + "#rotating an array ---> Codenation\n", |
| 93 | + "#marks = 1, difficulty = Basic\n", |
| 94 | + "'''\n", |
| 95 | + "Given an array of N size. The task is to rotate array by d elements where d is less than or equal to N.\n", |
| 96 | + "\n", |
| 97 | + "Input:\n", |
| 98 | + "The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of three lines. The first line of each test case consists of an integer N, where N is the size of array.\n", |
| 99 | + "The second line of each test case contains N space separated integers denoting array elements. The third line of each test case contains \"d\" .\n", |
| 100 | + "\n", |
| 101 | + "Output:\n", |
| 102 | + "Corresponding to each test case, in a new line, print the modified array.\n", |
| 103 | + "\n", |
| 104 | + "Constraints:\n", |
| 105 | + "1 ≤ T ≤ 200\n", |
| 106 | + "1 ≤ N ≤ 200\n", |
| 107 | + "1 ≤ A[i] ≤ 1000\n", |
| 108 | + "\n", |
| 109 | + "Example:\n", |
| 110 | + "Input\n", |
| 111 | + "1\n", |
| 112 | + "5\n", |
| 113 | + "1 2 3 4 5\n", |
| 114 | + "2\n", |
| 115 | + "\n", |
| 116 | + "Output\n", |
| 117 | + "3 4 5 1 2\n", |
| 118 | + "'''\n", |
| 119 | + "for _ in range(int(input())):\n", |
| 120 | + " m=int(input())\n", |
| 121 | + " a=list(map(int,input().split()))\n", |
| 122 | + " d=int(input())\n", |
| 123 | + " for j in range(m-d):\n", |
| 124 | + " print(a[j+d],end=' ')\n", |
| 125 | + " for j in range(d):\n", |
| 126 | + " print(a[j],end=' ')\n", |
| 127 | + " print()" |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "code", |
| 132 | + "execution_count": null, |
| 133 | + "metadata": {}, |
| 134 | + "outputs": [], |
| 135 | + "source": [] |
| 136 | + } |
| 137 | + ], |
| 138 | + "metadata": { |
| 139 | + "kernelspec": { |
| 140 | + "display_name": "Python 3", |
| 141 | + "language": "python", |
| 142 | + "name": "python3" |
| 143 | + }, |
| 144 | + "language_info": { |
| 145 | + "codemirror_mode": { |
| 146 | + "name": "ipython", |
| 147 | + "version": 3 |
| 148 | + }, |
| 149 | + "file_extension": ".py", |
| 150 | + "mimetype": "text/x-python", |
| 151 | + "name": "python", |
| 152 | + "nbconvert_exporter": "python", |
| 153 | + "pygments_lexer": "ipython3", |
| 154 | + "version": "3.7.5" |
| 155 | + } |
| 156 | + }, |
| 157 | + "nbformat": 4, |
| 158 | + "nbformat_minor": 2 |
| 159 | +} |
0 commit comments