Kindly help me to find logical error in the code
hello @7nishit
value of k is limited,so we should try to place large digit at its right place.

u are trying to put small value at its correct position first which may consume more number of operations.
refer this ->

Yes , I have kept that in mind that’s why have started from the back. Kindly provide a test case where your code and mine code gives different value. It would help me to find the difference.
i got ur approach,yeah this looks correct.
198 162
145 161 11 116 64 85 158 167 125 14 104 34 15 119 51 118 63 188 166 113 114 194 126 53 133 109 48 40 32 52 108 62 153 105 44 129 89 186 45 73 115 66 130 56 141 197 36 192 107 24 22 152 81 137 111 101 100 144 9 16 31 154 198 159 70 179 50 172 39 155 79 37 87 69 121 134 93 7 5 17 110 122 96 103 177 193 95 33 164 71 143 82 77 75 162 191 102 19 91 94 157 184 35 23 99 180 182 6 59 176 146 13 165 135 3 4 195 112 189 30 27 168 123 41 57 136 190 29 132 76 38 1 10 83 124 163 20 117 178 2 42 84 12 171 67 43 58 183 8 138 68 149 131 47 74 60 80 90 78 160 169 21 61 187 92 25 181 147 88 106 55 97 150 120 128 139 140 175 26 127 173 185 65 196 86 28 98 54 142 18 151 46 49 170 174 156 148 72
run ur code for this test case
It’s impossible for me to find the correct answer for this long test case that you sent. As you said that you understood my approach then kindly help me find the error.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.