-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff3d6b5
commit c192e25
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package Leetcode; | ||
|
||
public class RegularExpression { | ||
|
||
public static void main(String[] args) { | ||
|
||
} | ||
|
||
public boolean isMatch(String s, String p) { | ||
|
||
if() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package codingNinjas; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* "ninja-was-planning-to-propose-to-his-crush-nina-with-his-spectacular-martial-arts-moves-but-nina-was-more-interested-in-numbers-and-divisors-so-she-gave-ninja-a-challenge-to-complete-if-ninja-solves-it-only-then-she-will-date-him" | ||
Nina gave him an array of positive integers, ‘ARR’ and asked him to find the sum of divisors of the integers in ‘ARR’ with exactly four divisors. In case there is no such integer with exactly four divisors, then the answer is 0. Ninja has been struggling for a very long time, so he needs your help to solve the problem. | ||
The first line of input contains an integer 'T' representing the number of test cases. | ||
The first line of each test case contains an integer ‘N’ representing the number of integers in the array, ‘ARR’. | ||
The second line of each test case contains ‘N’ space-separated integers representing the elements of the ‘ARR’ array. | ||
For each test case, return the sum of divisors of the integers in ‘ARR’ with exactly four divisors. In case there is no such integer with exactly four divisors, then return 0. | ||
The output of each test case will be printed in a separate line. | ||
*/ | ||
public class Fourdivisors { | ||
|
||
public static int sumFourDivisors(ArrayList<Integer> arr, int n) { | ||
// Write your code here. | ||
int returnSum = 0; | ||
for (int i = 0; i < n; i++) { | ||
int sum = 0; | ||
int count = 0; | ||
for (int j = 1; j <= arr.get(i) / 2; j++) { | ||
if (arr.get(i) % j == 0) { | ||
count++; | ||
sum += j; | ||
} | ||
} | ||
count++; | ||
sum += arr.get(i); | ||
if (count == 4) { | ||
returnSum += sum; | ||
} | ||
} | ||
return returnSum; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package codingNinjas; | ||
|
||
public class MinimumDifferenceArray { | ||
|
||
|
||
static int minDiff(int n, int[] arr) { | ||
// Write your code here. | ||
int min=Integer.MAX_VALUE; | ||
for(int i=0;i<n-1;i++){ | ||
if(min==0) return min; | ||
for(int j=i+1;j<n;j++){ | ||
int k=arr[i]-arr[j]; | ||
if(k<0) k=-k; | ||
if(min>k) min=k; | ||
} | ||
} | ||
return min; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package codingNinjas; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class PairSum { | ||
|
||
public static List<int[]> pairSum(int[] arr, int s) { | ||
// Write your code here. | ||
List<int[]> ls = new ArrayList<int[]>(); | ||
Arrays.sort(arr); | ||
for(int i=0;i<arr.length-1;i++){ | ||
|
||
for(int j=i+1;j<arr.length;j++){ | ||
int[] x= new int[2]; | ||
if((arr[i]+arr[j])==s) { | ||
|
||
x[0]=arr[i];x[1]=arr[j]; | ||
|
||
ls.add(x); | ||
} | ||
} | ||
} | ||
return ls; | ||
} | ||
} |