-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay96
99 lines (77 loc) · 2.7 KB
/
Day96
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
// A. Fafa and his Company
//import java.util.Scanner;
public class FafaAndHisCompany {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int count = 0;
// Loop through all possible values of l from 1 to n-1
for (int l = 1; l < n; l++) {
if ((n - l) % l == 0) {
count++;
}
}
System.out.println(count);
scanner.close();
}
}
//B. Triple
//https://codeforces.com/problemset/problem/1669/B
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt(); // Read number of test cases
for (int i = 0; i < t; i++) {
int n = scanner.nextInt(); // Read the size of the array
int[] a = new int[n];
// Read the elements of the array
for (int j = 0; j < n; j++) {
a[j] = scanner.nextInt();
}
System.out.println(findTriplet(a));
}
scanner.close();
}
private static int findTriplet(int[] a) {
Map<Integer, Integer> frequency = new HashMap<>();
// Count frequencies of each number
for (int num : a) {
frequency.put(num, frequency.getOrDefault(num, 0) + 1);
}
// Check for any number that appears at least three times
for (Map.Entry<Integer, Integer> entry : frequency.entrySet()) {
if (entry.getValue() >= 3) {
return entry.getKey(); // Return the first number found
}
}
return -1; // If no number appears at least three times
}
}
//345. Reverse Vowels of a String
// https://leetcode.com/problems/reverse-vowels-of-a-string/?envType=study-plan-v2&envId=leetcode-75
class Solution {
public String reverseVowels(String s) {
char[] word = s.toCharArray();
int start = 0;
int end = s.length() - 1;
String vowels = "aeiouAEIOU";
while (start < end) {
while (start < end && vowels.indexOf(word[start]) == -1) {
start++;
}
while (start < end && vowels.indexOf(word[end]) == -1) {
end--;
}
char temp = word[start];
word[start] = word[end];
word[end] = temp;
start++;
end--;
}
String answer = new String(word);
return answer;
}
}