-
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
15b0ba0
commit 816d947
Showing
18 changed files
with
400 additions
and
249 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 |
---|---|---|
@@ -1,51 +1,51 @@ | ||
# Sample workflow for building and deploying a Jekyll site to GitHub Pages | ||
name: Deploy Jekyll with GitHub Pages dependencies preinstalled | ||
|
||
on: | ||
# Runs on pushes targeting the default branch | ||
push: | ||
branches: ["main"] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | ||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
# Build job | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Pages | ||
uses: actions/configure-pages@v4 | ||
- name: Build with Jekyll | ||
uses: actions/jekyll-build-pages@v1 | ||
with: | ||
source: ./ | ||
destination: ./_site | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
|
||
# Deployment job | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 | ||
# Sample workflow for building and deploying a Jekyll site to GitHub Pages | ||
name: Deploy Jekyll with GitHub Pages dependencies preinstalled | ||
|
||
on: | ||
# Runs on pushes targeting the default branch | ||
push: | ||
branches: ["main"] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | ||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
# Build job | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Pages | ||
uses: actions/configure-pages@v4 | ||
- name: Build with Jekyll | ||
uses: actions/jekyll-build-pages@v1 | ||
with: | ||
source: ./ | ||
destination: ./_site | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
|
||
# Deployment job | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |
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 |
---|---|---|
@@ -1,58 +1,58 @@ | ||
//{ 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()); // Inputting the testcases | ||
while(t-->0) | ||
{ | ||
long n = Long.parseLong(br.readLine().trim()); | ||
long a[] = new long[(int)(n)]; | ||
// long getAnswer[] = new long[(int)(n)]; | ||
String inputLine[] = br.readLine().trim().split(" "); | ||
for (int i = 0; i < n; i++) { | ||
a[i] = Long.parseLong(inputLine[i]); | ||
} | ||
|
||
Solution obj = new Solution(); | ||
System.out.println(obj.countSub(a, n) ? 1:0); | ||
|
||
} | ||
} | ||
} | ||
|
||
|
||
// } Driver Code Ends | ||
|
||
|
||
//User function Template for Java | ||
|
||
|
||
class Solution | ||
{ | ||
public boolean countSub(long arr[], long n) | ||
{ | ||
// Your code goes here | ||
for (int i = 0; i <= (n - 2) / 2; i++) | ||
{ | ||
if (arr[2 * i + 1] > arr[i]) | ||
{ | ||
return false; | ||
} | ||
|
||
if (2 * i + 2 < n && arr[2 * i + 2] > arr[i]) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
//{ 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()); // Inputting the testcases | ||
while(t-->0) | ||
{ | ||
long n = Long.parseLong(br.readLine().trim()); | ||
long a[] = new long[(int)(n)]; | ||
// long getAnswer[] = new long[(int)(n)]; | ||
String inputLine[] = br.readLine().trim().split(" "); | ||
for (int i = 0; i < n; i++) { | ||
a[i] = Long.parseLong(inputLine[i]); | ||
} | ||
|
||
Solution obj = new Solution(); | ||
System.out.println(obj.countSub(a, n) ? 1:0); | ||
|
||
} | ||
} | ||
} | ||
|
||
|
||
// } Driver Code Ends | ||
|
||
|
||
//User function Template for Java | ||
|
||
|
||
class Solution | ||
{ | ||
public boolean countSub(long arr[], long n) | ||
{ | ||
// Your code goes here | ||
for (int i = 0; i <= (n - 2) / 2; i++) | ||
{ | ||
if (arr[2 * i + 1] > arr[i]) | ||
{ | ||
return false; | ||
} | ||
|
||
if (2 * i + 2 < n && arr[2 * i + 2] > arr[i]) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Time complexity - O(n) | ||
Space complexity - O(1) | ||
Time complexity - O(n) | ||
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 |
---|---|---|
@@ -1,64 +1,64 @@ | ||
//{ 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) { | ||
String s1 = br.readLine().trim(); | ||
String[] S1 = s1.split(" "); | ||
int n = Integer.parseInt(S1[0]); | ||
int k = Integer.parseInt(S1[1]); | ||
String s2 = br.readLine().trim(); | ||
String[] S2 = s2.split(" "); | ||
int[] nums = new int[n]; | ||
for (int i = 0; i < n; i++) { | ||
nums[i] = Integer.parseInt(S2[i]); | ||
} | ||
Solution ob = new Solution(); | ||
boolean ans = ob.canPair(nums, k); | ||
if (ans) | ||
System.out.println("True"); | ||
else | ||
System.out.println("False"); | ||
} | ||
} | ||
} | ||
|
||
// } Driver Code Ends | ||
|
||
|
||
// User function Template for Java | ||
|
||
class Solution | ||
{ | ||
public boolean canPair(int[] nums, int k) | ||
{ | ||
// Code here | ||
int[] dp = new int[k]; | ||
for(int a : nums) | ||
{ | ||
int t = a % k; | ||
if(t<0) | ||
t += k; | ||
|
||
dp[t]++; | ||
} | ||
|
||
if(dp[0] % 2 != 0) | ||
return false; | ||
|
||
for(int i=1; i<=k/2; i++) | ||
{ | ||
if(dp[k-i] != dp[i]) | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
//{ 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) { | ||
String s1 = br.readLine().trim(); | ||
String[] S1 = s1.split(" "); | ||
int n = Integer.parseInt(S1[0]); | ||
int k = Integer.parseInt(S1[1]); | ||
String s2 = br.readLine().trim(); | ||
String[] S2 = s2.split(" "); | ||
int[] nums = new int[n]; | ||
for (int i = 0; i < n; i++) { | ||
nums[i] = Integer.parseInt(S2[i]); | ||
} | ||
Solution ob = new Solution(); | ||
boolean ans = ob.canPair(nums, k); | ||
if (ans) | ||
System.out.println("True"); | ||
else | ||
System.out.println("False"); | ||
} | ||
} | ||
} | ||
|
||
// } Driver Code Ends | ||
|
||
|
||
// User function Template for Java | ||
|
||
class Solution | ||
{ | ||
public boolean canPair(int[] nums, int k) | ||
{ | ||
// Code here | ||
int[] dp = new int[k]; | ||
for(int a : nums) | ||
{ | ||
int t = a % k; | ||
if(t<0) | ||
t += k; | ||
|
||
dp[t]++; | ||
} | ||
|
||
if(dp[0] % 2 != 0) | ||
return false; | ||
|
||
for(int i=1; i<=k/2; i++) | ||
{ | ||
if(dp[k-i] != dp[i]) | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Time Complexity - O(n) | ||
Space Complexity - O(k) | ||
Time Complexity - O(n) | ||
Space Complexity - O(k) |
Oops, something went wrong.