Skip to content

Commit

Permalink
adding new folder
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishektripathi66 committed Dec 2, 2023
1 parent ff3d6b5 commit c192e25
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Leetcode/RegularExpression.java
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()
}
}
39 changes: 39 additions & 0 deletions codingNinjas/Fourdivisors.java
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;
}
}
18 changes: 18 additions & 0 deletions codingNinjas/MinimumDifferenceArray.java
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;
}
27 changes: 27 additions & 0 deletions codingNinjas/PairSum.java
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;
}
}

0 comments on commit c192e25

Please sign in to comment.