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.
#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>/** * Let's say we have an array defined, arr[N]. * Let's fill this array with some arbitrary input. * Same format from the challenge. * -- INPUT -- * 3 * 2 3 1 * -- DONE -- * * Thus, arr[] has three members: * arr = { 2, 3, 1 } * * Let's use 1-indexing: * arr[1] = 2 * arr[2] = 3 * arr[3] = 1 * * Our objective is the following: * Let's output, in sequence, the array indices for which * '1', '2', '3', ... , N value(s) are stored. * * In words (1-indexing): * Value '1' @ arr[3], so print '3'. * Value '2' @ arr[1], so print '1'. * Value '3' @ arr[2], so print '2'. * ^ ^ * | | * for-loop output * * Given the above explanation, the mathematical explanation * provided by the challenge should be a little more clear!**/intmain(){intn;scanf("%d\n",&n);int*y_values=(int*)malloc(sizeof(int)*n);// INPUTfor(inti=0;i<n;i++)scanf("%d ",&y_values[i]);// BASIC SEARCHfor(inti=1;i<=n;i++){for(intj=0;j<n;j++){if(y_values[j]==i)printf("%d\n",j+1);}}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Security Function Inverses
You are viewing a single comment's thread. Return to all comments →