File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,26 @@ public static int[] constructRandomUniqueElementsArray() {
4545 return set .stream ().mapToInt (Integer ::intValue ).toArray ();
4646 }
4747
48+ /**
49+ * Generate integer array of size range and each element between 1 to range
50+ *
51+ * @param range elements value will be between 1 to range
52+ * @return int array
53+ */
54+ public static int [] constructArrayWithinRange (int range ) {
55+ Set <Integer > set = new HashSet <Integer >();
56+ int [] arr = new int [range ];
57+ int index = 0 ;
58+ while (index < range ) {
59+ int data = AlgoUtils .random (range ) + 1 ;
60+ if (!set .contains (data )) {
61+ arr [index ++] = data ;
62+ set .add (data );
63+ }
64+ }
65+ return arr ;
66+ }
67+
4868 /**
4969 * Generate random integer array of size between 5 and 10
5070 * and value will be in range of 0 to 15
You can’t perform that action at this time.
0 commit comments