Skip to content

Commit

Permalink
Added codes for 15 Feb
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Feb 15, 2024
1 parent 6c6e2bf commit ea9cdff
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
57 changes: 57 additions & 0 deletions GeeksForGeeks/February/15-2-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//{ Driver Code Starts
//Initial Template for Java

import java.util.*;
import java.lang.*;
import java.io.*;
class GFG
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
while(T-->0)
{
int n = Integer.parseInt(br.readLine().trim());
int[][] paths = new int[n][n];
for(int i = 0; i < n; i++){
String[] s = br.readLine().trim().split(" ");
for(int j = 0; j < n; j++){
paths[i][j] = Integer.parseInt(s[j]);
}
}
Solution obj = new Solution();
int ans = obj.isPossible(paths);
System.out.println(ans);

}
}
}

// } Driver Code Ends


//User function Template for Java

class Solution
{
public int isPossible(int[][] paths)
{
// Code here
for(int i=0;i<paths.length;i++)
{
int cnt = 0;

for(int j=0;j<paths[0].length;j++)
{
cnt+=paths[i][j];
}

if(cnt%2!=0)
{
return 0;
}
}
return 1;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/February/15-2-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n^2)
Space complexity - O(1)
2 changes: 2 additions & 0 deletions LeetCode/February/15-2-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(sort)
Space complexity - O(sort)
18 changes: 18 additions & 0 deletions LeetCode/February/15-2-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution
{
public long largestPerimeter(int[] nums)
{
long prefix = Arrays.stream(nums).asLongStream().sum();

Arrays.sort(nums);

for (int i = nums.length - 1; i >= 2; --i)
{
prefix -= nums[i];
if (prefix > nums[i])
return prefix + nums[i];
}

return -1;
}
}

0 comments on commit ea9cdff

Please sign in to comment.