From 3f395901fba06e5f9f7d5f73c4f843e921965169 Mon Sep 17 00:00:00 2001 From: 149ps Date: Sun, 5 Jun 2022 12:15:16 -0700 Subject: [PATCH 1/2] O(nlogn) time and O(n) space using sorting. --- ...Array Such That Maximum Difference Is K.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 2294. Partition Array Such That Maximum Difference Is K/2294. Partition Array Such That Maximum Difference Is K.py diff --git a/2294. Partition Array Such That Maximum Difference Is K/2294. Partition Array Such That Maximum Difference Is K.py b/2294. Partition Array Such That Maximum Difference Is K/2294. Partition Array Such That Maximum Difference Is K.py new file mode 100644 index 0000000..06c852c --- /dev/null +++ b/2294. Partition Array Such That Maximum Difference Is K/2294. Partition Array Such That Maximum Difference Is K.py @@ -0,0 +1,45 @@ +""" +You are given an integer array nums and an integer k. You may partition nums into one or more subsequences such that each element in nums appears in exactly one of the subsequences. + +Return the minimum number of subsequences needed such that the difference between the maximum and minimum values in each subsequence is at most k. + +A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. + +Example 1: + +Input: nums = [3,6,1,2,5], k = 2 +Output: 2 +Explanation: +We can partition nums into the two subsequences [3,1,2] and [6,5]. +The difference between the maximum and minimum value in the first subsequence is 3 - 1 = 2. +The difference between the maximum and minimum value in the second subsequence is 6 - 5 = 1. +Since two subsequences were created, we return 2. It can be shown that 2 is the minimum number of subsequences needed. +Example 2: + +Input: nums = [1,2,3], k = 1 +Output: 2 +Explanation: +We can partition nums into the two subsequences [1,2] and [3]. +The difference between the maximum and minimum value in the first subsequence is 2 - 1 = 1. +The difference between the maximum and minimum value in the second subsequence is 3 - 3 = 0. +Since two subsequences were created, we return 2. Note that another optimal solution is to partition nums into the two subsequences [1] and [2,3]. +Example 3: + +Input: nums = [2,2,4,5], k = 0 +Output: 3 +Explanation: +We can partition nums into the three subsequences [2,2], [4], and [5]. +The difference between the maximum and minimum value in the first subsequences is 2 - 2 = 0. +The difference between the maximum and minimum value in the second subsequences is 4 - 4 = 0. +The difference between the maximum and minimum value in the third subsequences is 5 - 5 = 0. +Since three subsequences were created, we return 3. It can be shown that 3 is the minimum number of subsequences needed. +""" +class Solution: + def partitionArray(self, nums: List[int], k: int) -> int: + nums.sort() + min_val,result = -sys.maxsize-1,0 + for num in nums: + if num > min_val + k: + min_val = num + result += 1 + return result \ No newline at end of file From c18874f28151804de92002b5c256aba152de0766 Mon Sep 17 00:00:00 2001 From: Parth Shah <5869983+149ps@users.noreply.github.com> Date: Sat, 7 Sep 2024 18:31:18 -0700 Subject: [PATCH 2/2] Create static.yml --- .github/workflows/static.yml | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/static.yml diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..f2c9e97 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,43 @@ +# Simple workflow for deploying static content to GitHub Pages +name: Deploy static content to Pages + +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: + # Single deploy job since we're just deploying + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v5 + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + # Upload entire repository + path: '.' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4