From ef36cab5c4e944b1aa59048f65bdcb4e209e9ee5 Mon Sep 17 00:00:00 2001 From: Tanmay-312 Date: Mon, 17 Jun 2024 11:16:55 +0530 Subject: [PATCH] Added codes for 17 June --- GeeksForGeeks/June/17-6-24/GFG.java | 66 ++++++++++++++++++++++++++++ GeeksForGeeks/June/17-6-24/README.md | 2 + LeetCode/June/17-6-24/README.md | 2 + LeetCode/June/17-6-24/Solution.java | 21 +++++++++ 4 files changed, 91 insertions(+) create mode 100644 GeeksForGeeks/June/17-6-24/GFG.java create mode 100644 GeeksForGeeks/June/17-6-24/README.md create mode 100644 LeetCode/June/17-6-24/README.md create mode 100644 LeetCode/June/17-6-24/Solution.java diff --git a/GeeksForGeeks/June/17-6-24/GFG.java b/GeeksForGeeks/June/17-6-24/GFG.java new file mode 100644 index 0000000..a923100 --- /dev/null +++ b/GeeksForGeeks/June/17-6-24/GFG.java @@ -0,0 +1,66 @@ +//{ Driver Code Starts +// Initial Template for Java + +import java.io.*; +import java.util.*; + +class GFG { + public static void main(String args[]) throws IOException { + BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(read.readLine()); + while (t-- > 0) { + int p1[] = new int[2]; + int q1[] = new int[2]; + int p2[] = new int[2]; + int q2[] = new int[2]; + String S1[] = read.readLine().split(" "); + p1[0] = Integer.parseInt(S1[0]); + p1[1] = Integer.parseInt(S1[1]); + q1[0] = Integer.parseInt(S1[2]); + q1[1] = Integer.parseInt(S1[3]); + String S2[] = read.readLine().split(" "); + p2[0] = Integer.parseInt(S2[0]); + p2[1] = Integer.parseInt(S2[1]); + q2[0] = Integer.parseInt(S2[2]); + q2[1] = Integer.parseInt(S2[3]); + Solution ob = new Solution(); + String ans = ob.doIntersect(p1, q1, p2, q2); + // if(ans) + System.out.println(ans); + // else + // System.out.println("false"); + } + } +} +// } Driver Code Ends + + +// User function Template for Java + +class Solution +{ + String doIntersect(int p1[], int q1[], int p2[], int q2[]) + { + // code here + double m1 = (double)(q1[1] - p1[1]) / (double)(q1[0] - p1[0]); + double m2 = (double)(q2[1] - p2[1]) / (double)(q2[0] - p2[0]); + + if (m1 == m2) + return "false"; + + boolean chk211 = p2[1]-p1[1] - m1*(p2[0]-p1[0]) > 0 ? true : false; + boolean chk212 = q2[1]-p1[1] - m1*(q2[0]-p1[0]) > 0 ? true : false; + boolean chk121 = p1[1]-p2[1] - m2*(p1[0]-p2[0]) > 0 ? true : false; + boolean chk122 = q1[1]-p2[1] - m2*(q1[0]-p2[0]) > 0 ? true : false; + + if ((chk211==true && chk212 == true) || + (chk211==false && chk212 == false) || + (chk121 == true && chk122 == true) || + (chk121 == false && chk122 == false)) + { + return "false"; + } + + return "true"; + } +} diff --git a/GeeksForGeeks/June/17-6-24/README.md b/GeeksForGeeks/June/17-6-24/README.md new file mode 100644 index 0000000..b85bed6 --- /dev/null +++ b/GeeksForGeeks/June/17-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(1) +Space complexity - O(1) diff --git a/LeetCode/June/17-6-24/README.md b/LeetCode/June/17-6-24/README.md new file mode 100644 index 0000000..0352e7f --- /dev/null +++ b/LeetCode/June/17-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(sqrt(c)) +Space complexity - O(1) diff --git a/LeetCode/June/17-6-24/Solution.java b/LeetCode/June/17-6-24/Solution.java new file mode 100644 index 0000000..6e359b0 --- /dev/null +++ b/LeetCode/June/17-6-24/Solution.java @@ -0,0 +1,21 @@ +class Solution +{ + public boolean judgeSquareSum(int c) + { + long l = 0; + long r = (long) Math.sqrt(c); + + while (l <= r) + { + long sum = l * l + r * r; + if (sum == c) + return true; + if (sum < c) + l++; + else + r--; + } + + return false; + } +}