-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay09.js
More file actions
239 lines (172 loc) · 4.22 KB
/
Day09.js
File metadata and controls
239 lines (172 loc) · 4.22 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// function numberPattern(N){
// let New = N+(N-1);
// let Lnew = N*2;
// let count = 1;
// for(let i=1; i<=New; i++)
// {
// let row = '';
// if(count<=N)
// {
// for(let j=1; j<=i; j++)
// {
// row = row+j;
// }
// console.log(row);
// count++;
// }
// else
// {
// for(let k=1; k<=(Lnew-i); k++)
// {
// row = row+k;
// }
// console.log(row);
// }
// }
// }
// Problem Statement: Given a square matrix, you have to find the reverse U
// traversal of the matrix. Refer the sample I/O for better understanding.
// Refer the given figure for better understanding.
// Note: No element should be visited more than once.
// let arr = [
// [1, 2, 3],
// [2, 4, 6],
// [4, 8, 12],
// ];
// let N = [0,1,2,3,4,3,2,1]
// for(let i=0; i<arr.length; i++)
// {
// for(let j=0; j<arr[i].length; j++)
// {
// if(i+j == N[i+j])
// {
// console.log(arr[i][j]);
// }
// }
// }
// Problem Statement:**You are given a number stored in a
// variable with the name N You have to print the pattern as
// shown below according to the value stored in N For example,
// consider the value stored in N = 5, then the required pattern will be.
// * * * * *
// *
// *
// *
// * * * * *
// let N = 5;
// for(let i=1; i<=N; i++)
// {
// if(i==1 || i==N)
// {
// let endToEnd = '';
// for(let j=1; j<=N; j++)
// {
// endToEnd+='* ';
// }
// console.log(endToEnd);
// }
// else
// {
// console.log('*');
// }
// }
// Problem Statement: You are given a 2D array, whose dimensions are stored in two variables with the name Nand M
// The value stored in N denotes the number of rows, and the value in M denotes the number of columns
// The 2D array is stored in a variable with the name arr
// You have to print the sum of indexes of the 2D array for all positions in the 2D array
// For example, consider the value stored in N = 3,M = 2, and the array is arr = [1,2],[3,4],[5,6], then the required output will be
// At index (0,0), the sum of indexes becomes (0 + 0 = 0)
// At index (0,1), the sum of indexes becomes (0 + 1 = 1)
// At index (1,0), the sum of indexes becomes (1 + 0 = 1)
// At index (1,1), the sum of indexes becomes (1 + 1 = 2)
// At index (2,0), the sum of indexes becomes (2 + 0 = 2)
// At index (2,1), the sum of indexes becomes (2 + 1 = 3)
// Therefore, the output becomes
// 0 1
// 1 2
// 2 3
// let arr = [
// [1, 2],
// [3, 4],
// [5, 6]
// ];
// let N = arr.length;
// let M = arr[0].length;
// // console.log(M);
// for(let i=0; i<N; i++)
// {
// let row = '';
// for(let j=0; j<M; j++)
// {
// sum = i+j;
// row=row+sum+' ';
// }
// console.log(row);
// }
// Problem Statement: Given amatrixwith N rows and M columns. Print the matrix elements starting from the top right corner and follow a zig-zag pattern.
// Look at the image for better understanding
// [
// [1,2,3,4,5],
// [6,7,8,9,1],
// [3,2,5,4,6],
// [7,8,9,1,2]
// ]
// For example, for the above matrix, the required output would be as shown below.
// 5 4 3 2 1 6 7 8 9 1 6 4 5 2 3 7 8 9 1 2.
// let arr = [
// [1,2,3,4,5],
// [6,7,8,9,1],
// [3,2,5,4,6],
// [7,8,9,1,2]
// ];
// let N = arr.length;
// let M = arr[0].length;
// let rowFinal = '';
// for(let i=0; i<N; i++)
// {
// if(i%2==0)
// {
// for(j=M-1; j>=0; j--)
// {
// rowFinal = rowFinal+arr[i][j]+' ';
// }
// }
// else
// {
// for(j=0; j<M; j++)
// {
// rowFinal = rowFinal+arr[i][j]+' ';
// }
// }
// }
// console.log(rowFinal);
// function reverseEvens(N,A){
// let count = 0;
// let even = '';
// for(let i=N-1; i>=0; i--)
// {
// if(A[i]%2==0)
// {
// even = even + A[i] +' ';
// count++;
// }
// }
// console.log(count);
// console.log(even);
// //write code here
// }
// function reverseOdds(N, A){
// let count = 0;
// let odd = '';
// for(let i=N-1; i>=0; i--)
// {
// if(A[i]%2!=0)
// {
// odd = odd + A[i] +' ';
// count++;
// }
// }
// console.log(count);
// console.log(odd);
// //write code here
// }