-
Notifications
You must be signed in to change notification settings - Fork 0
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
6c6e2bf
commit ea9cdff
Showing
4 changed files
with
79 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,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; | ||
} | ||
} |
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,2 @@ | ||
Time complexity - O(n^2) | ||
Space complexity - O(1) |
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,2 @@ | ||
Time complexity - O(sort) | ||
Space complexity - O(sort) |
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 @@ | ||
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; | ||
} | ||
} |