-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA1_linear_Search.java
More file actions
171 lines (121 loc) · 4.77 KB
/
DSA1_linear_Search.java
File metadata and controls
171 lines (121 loc) · 4.77 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
import java.util.Arrays;
public class DSA1_linear_Search {
public static void main(String[] args) {
//for 1
//int arr[] = { 12,54,56,-5, -6,-3,8};
// int ans = min(arr);
// System.out.println(ans);
//for 2
// int arr[][] = {
// {1,43,43,46}
// ,{-3,-4,7,78},
// {45,65,8,9}};
// int target = 9;
// int [] ans = Find_num(arr, target);
// System.out.println(Arrays.toString (ans));
//for 3
// int arr[][] = {
// {1,43,43,46}
// ,{-3,-4,7,78},
// {45,65,8,9}};
// System.out.println( Find_minNum(arr));
// System.out.println( Find_maxNum(arr));
//for 4;
// System.out.println(digits(456));
// System.out.println(even(67));
// int arr[]={23,3453,445,321,575,111111,56,87,9};
//System.out.println(findNum(arr));
// for 5 ;
int arr [] [] = { {23,45,322}, {455,2888}, {408 , 80 , 37}} ;
System.out.println(Richest(arr));
}
//question 1 :-to check a min number in array
// static int min (int [] arr ){
// int ans = arr[0];
// for (int i = 0; i < arr.length; i++) {
// if (arr[i] < ans ) {
// ans = arr[i]; }
// }
// return ans ;
// }
// question 2 :- check for number in 2D array
// static int [] Find_num (int [][] arr , int target){
// for (int row = 0; row < arr.length; row++) {
// for (int col = 0; col < arr[row].length; col++) {
// if (arr[row][col]==target){
// return new int[]{row,col};
// }
// }
// }
// return new int[]{-1,-1};
// }
// }
// question 3 = cheack min and max in 2D array
// static int Find_minNum (int [][] arr){
// int min = Integer.MAX_VALUE;
// for (int [] Row : arr) {
// for (int element : Row) {
// if (element < min){
// min = element;
// }
// }
// }
// return min;
// }
// static int Find_maxNum (int [][] arr){
// int max = Integer.MIN_VALUE;
// for (int [] Row : arr) {
// for (int element : Row) {
// if (element > max){
// max = element;
// }
// }
// }
// return max;
// }
// question 4 :- find even number that have even diogits in array
// find digit in number
/*static int digits(int num ){
if (num <0){
num = num * -1;
}
if (num ==0){
return 1 ;
}
int digit = 0;
while (num > 0) {
digit++;
num = num / 10 ;
}
return digit;
}
//find digits are even or odd
static boolean even( int num){
int noOfDigits = digits(num);
return noOfDigits % 2 == 0 ;
}
// make count of that number have even digits nd iterrate the array
static int findNum(int [] arr){
int count = 0;
for (int num : arr) {
if(even(num)){
count++;
}
}
return count;
}*/
// Queation 5:- find richest man in array [ { contain accounts and their balace}-1st person ..... ]
static int Richest( int allPeople[][] ){
int ans = Integer.MIN_VALUE;
for (int person = 0; person < allPeople.length; person++) {
int sum = 0;
for (int accounts = 0; accounts < allPeople[person].length; accounts++) {
sum += allPeople[person][accounts];
}
if (sum > ans){
ans = sum ;
}
}
return ans ;
}
}