Skip to content

Commit

Permalink
Added deployment for problems an new problems
Browse files Browse the repository at this point in the history
  • Loading branch information
vishal authored and vishal committed Jul 25, 2024
1 parent 9f4672f commit 6ed6800
Show file tree
Hide file tree
Showing 33 changed files with 216 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
build
docker-compose-private.yml
docker-compose-private.yml
.env
23 changes: 13 additions & 10 deletions .github/workflows/deploy-problems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ on:
- 'main'
paths:
- 'apps/problems/**'
- 'docker/problems/**'
- '.github/workflows/deploy-problems.yml'
pull_request:
branches:
- 'main'
paths:
- 'apps/problems/**'
- 'docker/problems/**'
- '.github/workflows/deploy-problems.yml'

jobs:
Deploy-sweeper:
Expand All @@ -20,22 +24,21 @@ jobs:
- name: Checkout the Repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Copy Docker image to root
run: cp ./docker/web/Dockerfile .

- name: Build Docker Image
run: docker build --build-arg DATABASE_URL=${{ secrets.DATABASE_URL }} -t vishal022/algoearth-problems:latest .

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build Docker Image
uses: docker/build-push-action@v2
with:
context: .
file: docker/problems/Dockerfile
push: true
tags: vishal022/algoearth-problems:latest
- name: Push to Docker Hub
run: docker push vishal022/algoearth-problems:latest


- name: Setup Kubectl
uses: azure/k8s-set-context@v1
Expand Down
57 changes: 57 additions & 0 deletions apps/problems/Intersting-Arrays/Problem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Interesting Array

## Problem Description

You have an array **A** with **N** elements. We have **two** types of operation available on this array:
1. We can split an element **B** into two elements, **C** and **D,** such that `B = C + D`.
2. We can merge two elements, **P** and **Q,** to one element, **R,** such that `R = P ^ Q` i.e., XOR of P and Q.

You have to determine whether it is possible to convert array A to size 1, **containing a single element equal to 0** after several splits and/or merge?

## Problem Constraints
- 1 <= N <= 100000
- 1 <= A[i] <= 10^6

## Input
The first argument is an integer array A of size N.

## Output Format
Return "Yes" if it is possible otherwise return "No".

## Example Input

Input 1:

```
A = [9, 17]
```

Input 2:
```
A = [1]
```

**Example Output**
Output 1:
```
Yes
```
Output 2:
```
No
```

**Example Explanation**
Explanation 1:
```
Following is one possible sequence of operations -
1.) Merge i.e 9 XOR 17 = 24
2.) Split 24 into two parts each of size 12
3.) Merge i.e 12 XOR 12 = 0
As there is only 1 element i.e 0. So it is possible.
```
Explanation 2:
```
There is no possible way to make it 0.
```
```
6 changes: 6 additions & 0 deletions apps/problems/Intersting-Arrays/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Problem Name: "Intersting Arrays"
Function Name: intersect
Input Structure:
Input Field: list<int> A
Output Structure:
Output Field: string ans
2 changes: 2 additions & 0 deletions apps/problems/Intersting-Arrays/tests/inputs/0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2
9 7
2 changes: 2 additions & 0 deletions apps/problems/Intersting-Arrays/tests/inputs/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
1
2 changes: 2 additions & 0 deletions apps/problems/Intersting-Arrays/tests/inputs/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2
1 2
2 changes: 2 additions & 0 deletions apps/problems/Intersting-Arrays/tests/inputs/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
3
3 5 6
2 changes: 2 additions & 0 deletions apps/problems/Intersting-Arrays/tests/inputs/4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
10
2 4 8 16 32 64 128 256 512 1024
2 changes: 2 additions & 0 deletions apps/problems/Intersting-Arrays/tests/inputs/5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
7
23 89 23 89 23 89 23
1 change: 1 addition & 0 deletions apps/problems/Intersting-Arrays/tests/outputs/0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Yes
1 change: 1 addition & 0 deletions apps/problems/Intersting-Arrays/tests/outputs/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No
1 change: 1 addition & 0 deletions apps/problems/Intersting-Arrays/tests/outputs/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No
1 change: 1 addition & 0 deletions apps/problems/Intersting-Arrays/tests/outputs/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Yes
1 change: 1 addition & 0 deletions apps/problems/Intersting-Arrays/tests/outputs/4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Yes
1 change: 1 addition & 0 deletions apps/problems/Intersting-Arrays/tests/outputs/5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No
52 changes: 52 additions & 0 deletions apps/problems/Kth-Smallest/Problem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## Problem: Kth Smallest Sum

### Description


Given two arrays `A` of size `N` and `B` of size `M`, and an integer `K`, you need to create a new array `C` of size `N*M` such that each element in `C` is the sum of an element from `A` and an element from `B`. Specifically, the array `C` will be formed by calculating `A[i] + B[j]` for all `1 ≤ i ≤ N` and `1 ≤ j ≤ M`. Your task is to find the Kth smallest element in the array `C`.

### Explanation
To clarify, consider arrays `A` and `B` as follows:
- Array `A` contains `N` elements: `A = [a1, a2, ..., aN]`
- Array `B` contains `M` elements: `B = [b1, b2, ..., bM]`

By adding every possible pair of elements `(ai, bj)` where `ai` is an element from `A` and `bj` is an element from `B`, you will generate a new array `C`. Array `C` will have `N * M` elements, with each element being the sum of an element from `A` and an element from `B`.

For example, if `A = [1, 2]` and `B = [3, 4]`, then the possible sums (i.e., elements of array `C`) would be:
- `1 + 3`
- `1 + 4`
- `2 + 3`
- `2 + 4`

So, array `C` would be `[4, 5, 5, 6]`.

The challenge is to find the Kth smallest element in this array `C` efficiently given the constraints.


### Constraints
- `1 ≤ N ≤ 10^6`, `1 ≤ M ≤ 10^6`, `1 ≤ K ≤ min(1e9,N*M)`.
- `(0 ≤ A[i] ≤ 10^4)`.
- `(0 ≤ B[j] ≤ 10^4)`.
- `min(N, M) ≤ 10^5`.

### Output Format
For each test case, print the Kth smallest element in the array `C`.

### Example

#### Input

```
N = 3
M = 3
K = 6
A = [1,2,3]
B = [4,5,6]
```

#### Output

```
7
```

8 changes: 8 additions & 0 deletions apps/problems/Kth-Smallest/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Problem Name: "Kth Smallest"
Function Name: solve
Input Structure:
Input Field: list<int> A
Input Field: list<int> B
Input Field: int K
Output Structure:
Output Field: int ans
5 changes: 5 additions & 0 deletions apps/problems/Kth-Smallest/tests/inputs/0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3
1 2 3
3
4 5 6
6
5 changes: 5 additions & 0 deletions apps/problems/Kth-Smallest/tests/inputs/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
2
3 4
2
5 6
4
5 changes: 5 additions & 0 deletions apps/problems/Kth-Smallest/tests/inputs/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
2
1 2
3
2 3 5
6
5 changes: 5 additions & 0 deletions apps/problems/Kth-Smallest/tests/inputs/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
4
10 6 9 2
6
1 5 5 3 9 4
14
5 changes: 5 additions & 0 deletions apps/problems/Kth-Smallest/tests/inputs/4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
9
5 7 5 6 1 1 2 4 2
3
8 7 8
8
5 changes: 5 additions & 0 deletions apps/problems/Kth-Smallest/tests/inputs/5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
2
9 3
5
10 5 8 1 1
4
1 change: 1 addition & 0 deletions apps/problems/Kth-Smallest/tests/outputs/0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7
1 change: 1 addition & 0 deletions apps/problems/Kth-Smallest/tests/outputs/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
1 change: 1 addition & 0 deletions apps/problems/Kth-Smallest/tests/outputs/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7
1 change: 1 addition & 0 deletions apps/problems/Kth-Smallest/tests/outputs/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12
1 change: 1 addition & 0 deletions apps/problems/Kth-Smallest/tests/outputs/4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
1 change: 1 addition & 0 deletions apps/problems/Kth-Smallest/tests/outputs/5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
21 changes: 19 additions & 2 deletions docker/problems/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
FROM alpine
FROM node:alpine

ARG DATABASE_URL

COPY ./package.json /usr/src/app/package.json
COPY ./package-lock.json /usr/src/app/package-lock.json
COPY ./turbo.json /usr/src/app/turbo.json
COPY ./packages /usr/src/app/packages
COPY ./apps/boilerplate-generator /usr/src/app/apps/boilerplate-generator
COPY ./apps/problems /usr/src/app/apps/problems

WORKDIR /usr/src/app

COPY ./apps/problems /usr/src/app/problems
RUN npm install

RUN cd ./apps/boilerplate-generator && npm run build && PROBLEMS_DIR_PATH=/usr/src/app/apps/problems node dist/index.js

WORKDIR /usr/src/app

RUN cd ./packages/db && DATABASE_URL=$DATABASE_URL npx prisma generate && DATABASE_URL=$DATABASE_URL MOUNT_PATH=/usr/src/app/apps/problems npx prisma db seed

WORKDIR /usr/src/app
2 changes: 1 addition & 1 deletion k8s/1-mount-problems/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
initContainers:
- name: copy-problems
image: vishal022/algoearth-problems:latest
command: ['sh', '-c', 'cp -r /usr/src/app/problems/* /problems']
command: ['sh', '-c', 'cp -r /usr/src/app/apps/problems/* /problems']
volumeMounts:
- name: problems
mountPath: /problems
Expand Down
4 changes: 4 additions & 0 deletions packages/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
build
docker-compose-private.yml
.env

0 comments on commit 6ed6800

Please sign in to comment.