public class PrimeNumberExample {
public static void main(String[] args) {
int i=0;
int num=0;
//Empty String
String primeNumbers = "";
for (i = 1; i <= 20000; i++)
{
int counter=0;
for(num =i; num>=1; num--)
{
if(i%num==0)
{
counter = counter + 1;
}
}
if (counter ==2)
{
//Appended the Prime number to the String
primeNumbers = primeNumbers + i + " ";
}
}
System.out.println("Prime numbers from 1 to 200,00 are :");
System.out.println(primeNumbers);
}
}
public static void main(String[] args) {
int i=0;
int num=0;
//Empty String
String primeNumbers = "";
for (i = 1; i <= 20000; i++)
{
int counter=0;
for(num =i; num>=1; num--)
{
if(i%num==0)
{
counter = counter + 1;
}
}
if (counter ==2)
{
//Appended the Prime number to the String
primeNumbers = primeNumbers + i + " ";
}
}
System.out.println("Prime numbers from 1 to 200,00 are :");
System.out.println(primeNumbers);
}
}
package com.Aman;public class Q27_1 { static int maxConsecutiveOnes(int x) { int count = 0; while (x!=0) { x = (x & (x << 1)); count++; } return count; } public static void main(String args[]) { int x = 1000; System.out.println(maxConsecutiveOnes(x)); }}public class Q29_1 { static void printAllSubsets(int[] A, int K) { int N = A.length; for (int i = 0; i < (1 << N); i++) { int sum = 0; for (int j = 0; j < N; j++) { if ((i & (1 << j)) > 0) sum += A[j]; } if (sum == K) { for (int j = 0; j < N; j++) { if ((i & (1 << j)) > 0) System.out.print(A[j] + " "); } System.out.println(); } } } public static void main(String[] args) { int[] A = {0, 1, 2, 3, 5, 6, 7, 11, 12, 14, 20}; int K = 5; printAllSubsets(A, K); }}public class Q26_1 { public static void main(String[] args) { int[]arr = {5,6,8,9,2,4,6,1}; int largest = arr[0]; int secondLargest = arr[0]; System.out.println("The given array is:"); for (int i = 0; i < arr.length; i++) { System.out.print(arr[i] + "\t"); } for (int i = 0; i < arr.length; i++) { if (arr[i] > largest) { secondLargest = largest; largest = arr[i]; } else if (arr[i] > secondLargest) { secondLargest = arr[i]; } } System.out.print("Second largest number is:" + secondLargest); }}
Java Hyd Team
public class Q29_1 { static void printAllSubsets(int[] A, int K) { int N = A.length; for (int i = 0; i < (1 << N); i++) { int sum = 0; for (int j = 0; j < N; j++) { if ((i & (1 << j)) > 0) …
public class Q29_2 { public static void main(String[] args) { int[] a = {0, 1, 2, 3, 5, 6, 7, 11, 12, 14, 20}; int n = 5; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a.length; j++) { if ((a[i] + a[j]) == n) { System.out.println("[" + i + "," + j + "]"); } } } }}3Sum
Medium
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
Notice that the solution set must not contain duplicate triplets.
Example 1:
Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]
Explanation:
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
The distinct triplets are [-1,0,1] and [-1,-1,2].
Notice that the order of the output and the order of the triplets does not matter.
Example 2:
Input: nums = [0,1,1]
Output: []
Explanation: The only possible triplet does not sum up to 0.
Example 3:
Input: nums = [0,0,0]
Output: [[0,0,0]]
Explanation: The only possible triplet sums up to 0.
Constraints:
3 <= nums.length <= 3000
-105 <= nums[i] <= 105
Medium
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
Notice that the solution set must not contain duplicate triplets.
Example 1:
Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]
Explanation:
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
The distinct triplets are [-1,0,1] and [-1,-1,2].
Notice that the order of the output and the order of the triplets does not matter.
Example 2:
Input: nums = [0,1,1]
Output: []
Explanation: The only possible triplet does not sum up to 0.
Example 3:
Input: nums = [0,0,0]
Output: [[0,0,0]]
Explanation: The only possible triplet sums up to 0.
Constraints:
3 <= nums.length <= 3000
-105 <= nums[i] <= 105
public class Q25_1 { public static void main(String[] args) { int[] arr = {5, 6, 8, 9, 2, 4, 6, 1}; int left = 0, right = arr.length - 1; while (left < right) { while (arr[left] % 2 == 0 && left < right) left++; while (arr[right] % 2 == 1 && left < right) right--; if (left < right) { int temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; left++; right--; } } System.out.println("Even numbers on left side and Odd numbers on right side: "); for (int i = 0; i < arr.length; i++) System.out.print(arr[i] + " "); }}public class Q24_1 { public static void main(String[] args) { int[] arr = {5, 6, 8, 9, 2, 4, 6, 1}; int toFind = 59; boolean found = search(arr, toFind); if (found) System.out.println(toFind + " is found"); else System.out.println(toFind + " is not found"); } /* * A method to search toFind in arr * arr: the array to search * toFind: the element to search */ public static boolean search(int[] arr, int toFind) { int left = 0; int right = arr.length - 1; while (left <= right) { int mid = (left + right) / 2; if (arr[mid] == toFind) { return true; } else if (arr[mid] < toFind) { left = mid + 1; } else { right = mid - 1; } } return false; }}Danaher Hiring for QA Engineer
Role: QA Enginee
Experience: Fresher
Passout year: 2022 and before
Location: Bangalore
Qualification: B.tech/BE/MCA/BCA
Salary: 4.9 - 6 LPA
Apply Now: https://jobs.danaher.com/global/en/job/DANAGLOBALR1191438EXTERNALENGLOBAL/QA-Engineer-I
Role: QA Enginee
Experience: Fresher
Passout year: 2022 and before
Location: Bangalore
Qualification: B.tech/BE/MCA/BCA
Salary: 4.9 - 6 LPA
Apply Now: https://jobs.danaher.com/global/en/job/DANAGLOBALR1191438EXTERNALENGLOBAL/QA-Engineer-I
public static void main(String[] args) { int i; int num; StringBuilder primeNumbers = new StringBuilder(); for (i = 1; i <= 100; i++) { int counter = 0; for (num = i; num >= 1; num--) { if (i % num == 0) { counter = counter + 1; } } if (counter == 2) { primeNumbers.append(i).append(" "); } } System.out.println("Prime numbers from 1 to 100 are :"); System.out.println(primeNumbers);Thinkitive is Hiring Software Trainee Engineer
Role - Trainee software engineer
Salary - 40K - 50k per month
Passout year - 2023, 2022, 2021
Qualification - B.E /B.Tech /M.Tech /MCA /MSC /BSC /BCA /
Location: Pune, Maharashtra
Apply now:https://docs.google.com/forms/d/e/1FAIpQLSfovPgY8oRTkE1QIGcmqnzjSXYvlATDYnwrB1rPo5sLwOLvXQ/viewform
Role - Trainee software engineer
Salary - 40K - 50k per month
Passout year - 2023, 2022, 2021
Qualification - B.E /B.Tech /M.Tech /MCA /MSC /BSC /BCA /
Location: Pune, Maharashtra
Apply now:https://docs.google.com/forms/d/e/1FAIpQLSfovPgY8oRTkE1QIGcmqnzjSXYvlATDYnwrB1rPo5sLwOLvXQ/viewform
Make The String Great
Easy
Given a string s of lower and upper case English letters.
A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:
0 <= i <= s.length - 2
s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa.
To make the string good, you can choose two adjacent characters that make the string bad and remove them. You can keep doing this until the string becomes good.
Return the string after making it good. The answer is guaranteed to be unique under the given constraints.
Notice that an empty string is also good.
Example 1:
Input: s = "leEeetcode"
Output: "leetcode"
Explanation: In the first step, either you choose i = 1 or i = 2, both will result "leEeetcode" to be reduced to "leetcode".
Example 2:
Input: s = "abBAcC"
Output: ""
Explanation: We have many possible scenarios, and all lead to the same answer. For example:
"abBAcC" --> "aAcC" --> "cC" --> ""
"abBAcC" --> "abBA" --> "aA" --> ""
Example 3:
Input: s = "s"
Output: "s"
Constraints:
1 <= s.length <= 100
s contains only lower and upper case English letters.
Easy
Given a string s of lower and upper case English letters.
A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:
0 <= i <= s.length - 2
s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa.
To make the string good, you can choose two adjacent characters that make the string bad and remove them. You can keep doing this until the string becomes good.
Return the string after making it good. The answer is guaranteed to be unique under the given constraints.
Notice that an empty string is also good.
Example 1:
Input: s = "leEeetcode"
Output: "leetcode"
Explanation: In the first step, either you choose i = 1 or i = 2, both will result "leEeetcode" to be reduced to "leetcode".
Example 2:
Input: s = "abBAcC"
Output: ""
Explanation: We have many possible scenarios, and all lead to the same answer. For example:
"abBAcC" --> "aAcC" --> "cC" --> ""
"abBAcC" --> "abBA" --> "aA" --> ""
Example 3:
Input: s = "s"
Output: "s"
Constraints:
1 <= s.length <= 100
s contains only lower and upper case English letters.
👍1
One thing to note is that to judge if two adjacent characters make a pair? We do easily tell that patterns like aA, Bb, cC are pairs, but how to implement the code? We can use the their ASCII values as reference, each character has a unique ASCII value:
a = 97, A = 65
b = 98, B = 66
c = 99, C = 67 ...
z = 122, Z = 90
Thus we can tell that two characters make a pair, when and only when their ASCII values differ by 323232 (Since the sentence only contains letters of alphabet, we do not need to consider about other speical characters). Keep This is a very common trick, keep it in mind!
Algorithm
If the size of string s is smaller than 2, return s directly.
Iterate over all adjacent characters in s.
If we find a pair, remove it from s, and start over from step 2.
Otherwise, we don't need to iterate. Move to step 3.
Return s as the final good string.
a = 97, A = 65
b = 98, B = 66
c = 99, C = 67 ...
z = 122, Z = 90
Thus we can tell that two characters make a pair, when and only when their ASCII values differ by 323232 (Since the sentence only contains letters of alphabet, we do not need to consider about other speical characters). Keep This is a very common trick, keep it in mind!
Algorithm
If the size of string s is smaller than 2, return s directly.
Iterate over all adjacent characters in s.
If we find a pair, remove it from s, and start over from step 2.
Otherwise, we don't need to iterate. Move to step 3.
Return s as the final good string.