-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRearrangeArraywithNospace.java
More file actions
50 lines (44 loc) · 1.03 KB
/
RearrangeArraywithNospace.java
File metadata and controls
50 lines (44 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public class RearrangeArraywithNospace
{
public static void print(int[] arr)
{
int n=arr.length;
for(int i=0;i<n;i++)
{
System.out.print(arr[i]+" ");
}
System.out.println("");
}
static void arrange(int arr[], int n)
{
int me=arr[n-1]+1;
int maxi=n-1;
int mini=0;
for(int i=0;i<n;i++)
{
if(i%2==0)
{
arr[i]=arr[i]+((arr[maxi]%me)*me);
maxi--;
}
else
{
arr[i]=arr[i]+((arr[mini]%me)*me);
mini++;
}
}
for(int i=0;i<n;i++)
{
arr[i]=(arr[i]/me);
}
// your code here
}
//TC:O(N)
//SP:O(1)
public static void main(String[] args) {
int[] arr = {0,1};
print(arr);
arrange(arr,arr.length);
print(arr);
}
}