GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leet-code/Java/Subarray Sum II.java at master · awangdev/leet-code

Expand file tree

/

Subarray Sum II.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
executable file
·
29 lines (25 loc) · 779 Bytes
/

Subarray Sum II.java

Copy path

File metadata and controls

executable file
·
29 lines (25 loc) · 779 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
H
tags: Two Pointers, Array, Binary Search
```
/*
Given an integer array, find a subarray where the sum of numbers is in a given interval.
Your code should return the number of possible answers. (The element in the array should be positive)
Example
Given [1,2,3,4] and interval = [1,3], return 4. The possible answers are:
[0, 0]
[0, 1]
[1, 1]
[2, 2]
*/
/*
Thoughts:
Brutle O(n2) with preSum can do. Do better: O(nlogn)
- presum
- iterate over start point, which will be the 'must have' index in result
- find the largest end point, where preSum[end] - preSum[start - 1] <= max. Binary Search since the presum will be increasing
- count += end - start + 1
- move on to next start
- Overall it should be O(nlogn)
- should write the binary search as a separate function
*/
```
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.