{"id":"1c2c27c5-d77c-4e05-8a41-7758b7a54602","name":"All Indices Of Array","description":"<p>1. You are given a number n, representing the count of elements. </p><p>2. You are given n numbers.</p><p>3. You are given a number x. </p><p>4. You are required to return the all indices at which x occurs in array a. </p><p>5. Return an array of appropriate size which contains all indices at which x occurs in array </p><p>6. If no such element exist print \"NO OUTPUT\" a. </p><p><br></p><p>Note -&gt; The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.</p>","inputFormat":"<p>A number n n1 n2 .. n number of elements A number x</p>","outputFormat":"<p>Return the array of indices from the allIndices function. Display is managed for you.</p>","constraints":"<p>1 &lt;= n &lt;= 10^4 0 &lt;= n1, n2, .. n elements &lt;= 10 ^ 3 0 &lt;= x &lt;= 10 ^ 3</p>","sampleCode":{"cpp":{"code":"#include <iostream>\r\n#include <vector>\r\nusing namespace std;\r\n\r\nvector<int> allIndex(vector<int>& arr, int idx, int data, int count)\r\n{\r\n\r\n}\r\n\r\nint main() {\r\n int n ;\r\n cin >> n;\r\n vector<int> arr;\r\n for (int i = 0; i < n; i++) {\r\n int d;\r\n cin >> d;\r\n arr.push_back(d);\r\n }\r\n int data;\r\n cin >> data;\r\n vector<int> ans = allIndex(arr, 0, data, 0);\r\n if (ans.size() == 0) {\r\n cout << endl;\r\n return 0;\r\n }\r\n for (int ele : ans) cout << ele << endl;\r\n\r\n return 0;\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n int n = Integer.parseInt(br.readLine());\r\n int[] arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = Integer.parseInt(br.readLine());\r\n }\r\n int x = Integer.parseInt(br.readLine());\r\n int[] iarr = allIndices(arr, x, 0, 0);\r\n\r\n if(iarr.length == 0){\r\n System.out.println();\r\n return;\r\n }\r\n\r\n for(int i = 0; i < iarr.length; i++){\r\n System.out.println(iarr[i]);\r\n }\r\n }\r\n\r\n public static int[] allIndices(int[] arr, int x, int idx, int fsf) {\r\n // write ur code here\r\n }\r\n\r\n}"},"python":{"code":"import sys\nsys.setrecursionlimit (10000)\ndef allindices(arr,x,idx,fsf):\n# Write your code here\n \ndef main():\n n=int(input())\n arr=[]\n for i in range(n):\n ele=int(input())\n arr.append(ele)\n x=int(input())\n \n iarr=allindices(arr,x,0,0)\n \n for i in range(len(iarr)):\n print(iarr[i])\n \nmain()"}},"points":10,"difficulty":"easy","sampleInput":"6\r\n15\r\n11\r\n40\r\n4\r\n4\r\n9\r\n4","sampleOutput":"3\r\n4","questionVideo":"https://www.youtube.com/embed/TYIZmI5FesU","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"f6239c9f-6df9-4db2-8667-364d7809a834","name":"All Indices Of Array","slug":"all-indices-of-array","type":1}],"next":{"id":"390199fc-127e-4c58-9e6f-66d4c9020b34","name":"All Indices In An Array","type":3,"slug":"all-indices-in-an-array"},"prev":{"id":"d164c462-19e3-4756-93ea-b5a5f4852f89","name":"Last Index","type":3,"slug":"last-index"}}}

All Indices Of Array

<p>1. You are given a number n, representing the count of elements. </p><p>2. You are given n numbers.</p><p>3. You are given a number x. </p><p>4. You are required to return the all indices at which x occurs in array a. </p><p>5. Return an array of appropriate size which contains all indices at which x occurs in array </p><p>6. If no such element exist print "NO OUTPUT" a. </p><p><br></p><p>Note -&gt; The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.</p>

{"id":"1c2c27c5-d77c-4e05-8a41-7758b7a54602","name":"All Indices Of Array","description":"<p>1. You are given a number n, representing the count of elements. </p><p>2. You are given n numbers.</p><p>3. You are given a number x. </p><p>4. You are required to return the all indices at which x occurs in array a. </p><p>5. Return an array of appropriate size which contains all indices at which x occurs in array </p><p>6. If no such element exist print \"NO OUTPUT\" a. </p><p><br></p><p>Note -&gt; The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.</p>","inputFormat":"<p>A number n n1 n2 .. n number of elements A number x</p>","outputFormat":"<p>Return the array of indices from the allIndices function. Display is managed for you.</p>","constraints":"<p>1 &lt;= n &lt;= 10^4 0 &lt;= n1, n2, .. n elements &lt;= 10 ^ 3 0 &lt;= x &lt;= 10 ^ 3</p>","sampleCode":{"cpp":{"code":"#include <iostream>\r\n#include <vector>\r\nusing namespace std;\r\n\r\nvector<int> allIndex(vector<int>& arr, int idx, int data, int count)\r\n{\r\n\r\n}\r\n\r\nint main() {\r\n int n ;\r\n cin >> n;\r\n vector<int> arr;\r\n for (int i = 0; i < n; i++) {\r\n int d;\r\n cin >> d;\r\n arr.push_back(d);\r\n }\r\n int data;\r\n cin >> data;\r\n vector<int> ans = allIndex(arr, 0, data, 0);\r\n if (ans.size() == 0) {\r\n cout << endl;\r\n return 0;\r\n }\r\n for (int ele : ans) cout << ele << endl;\r\n\r\n return 0;\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n int n = Integer.parseInt(br.readLine());\r\n int[] arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = Integer.parseInt(br.readLine());\r\n }\r\n int x = Integer.parseInt(br.readLine());\r\n int[] iarr = allIndices(arr, x, 0, 0);\r\n\r\n if(iarr.length == 0){\r\n System.out.println();\r\n return;\r\n }\r\n\r\n for(int i = 0; i < iarr.length; i++){\r\n System.out.println(iarr[i]);\r\n }\r\n }\r\n\r\n public static int[] allIndices(int[] arr, int x, int idx, int fsf) {\r\n // write ur code here\r\n }\r\n\r\n}"},"python":{"code":"import sys\nsys.setrecursionlimit (10000)\ndef allindices(arr,x,idx,fsf):\n# Write your code here\n \ndef main():\n n=int(input())\n arr=[]\n for i in range(n):\n ele=int(input())\n arr.append(ele)\n x=int(input())\n \n iarr=allindices(arr,x,0,0)\n \n for i in range(len(iarr)):\n print(iarr[i])\n \nmain()"}},"points":10,"difficulty":"easy","sampleInput":"6\r\n15\r\n11\r\n40\r\n4\r\n4\r\n9\r\n4","sampleOutput":"3\r\n4","questionVideo":"https://www.youtube.com/embed/TYIZmI5FesU","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"f6239c9f-6df9-4db2-8667-364d7809a834","name":"All Indices Of Array","slug":"all-indices-of-array","type":1}],"next":{"id":"390199fc-127e-4c58-9e6f-66d4c9020b34","name":"All Indices In An Array","type":3,"slug":"all-indices-in-an-array"},"prev":{"id":"d164c462-19e3-4756-93ea-b5a5f4852f89","name":"Last Index","type":3,"slug":"last-index"}}}
plane

Editor


Loading...

All Indices Of Array

easy

1. You are given a number n, representing the count of elements.

2. You are given n numbers.

3. You are given a number x.

4. You are required to return the all indices at which x occurs in array a.

5. Return an array of appropriate size which contains all indices at which x occurs in array

6. If no such element exist print "NO OUTPUT" a.


Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

Constraints

1 <= n <= 10^4 0 <= n1, n2, .. n elements <= 10 ^ 3 0 <= x <= 10 ^ 3

Format

Input

A number n n1 n2 .. n number of elements A number x

Output

Return the array of indices from the allIndices function. Display is managed for you.

Example

Sample Input

6 15 11 40 4 4 9 4

Sample Output

3 4

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode