585. Investments in 2016 LeetCode Solution

In this guide, you will get 585. Investments in 2016 LeetCode Solution with the best time and space complexity. The solution to Investments in problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.

Table of Contents

  1. Problem Statement
  2. Complexity Analysis
  3. Investments in solution in C++
  4. Investments in solution in Java
  5. Investments in solution in Python
  6. Additional Resources
585. Investments in 2016LeetCode Solution image

Problem Statement of Investments in

Table: Insurance

+————-+——-+
| Column Name | Type |
+————-+——-+
| pid | int |
| tiv_2015 | float |
| tiv_2016 | float |
| lat | float |
| lon | float |
+————-+——-+
pid is the primary key (column with unique values) for this table.
Each row of this table contains information about one policy where:
pid is the policyholder’s policy ID.
tiv_2015 is the total investment value in 2015 and tiv_2016 is the total investment value in 2016.
lat is the latitude of the policy holder’s city. It’s guaranteed that lat is not NULL.
lon is the longitude of the policy holder’s city. It’s guaranteed that lon is not NULL.

Write a solution to report the sum of all total investment values in 2016 tiv_2016, for all policyholders who:

have the same tiv_2015 value as one or more other policyholders, and
are not located in the same city as any other policyholder (i.e., the (lat, lon) attribute pairs must be unique).

Round tiv_2016 to two decimal places.
The result format is in the following example.

Example not found

Constraints not found

Complexity Analysis

  • Time Complexity: Google AdSense
  • Space Complexity: Google Analytics

585. Investments in 2016 LeetCode Solution in C++

WITH
  InsuranceWithCounts AS (
    SELECT
      tiv_2016,
      COUNT(*) OVER(PARTITION by tiv_2015) AS tiv_2015_count,
      COUNT(*) OVER(PARTITION by lat, lon) AS city_count
    FROM Insurance
  )
SELECT ROUND(SUM(tiv_2016), 2) AS tiv_2016
FROM InsuranceWithCounts
WHERE tiv_2015_count > 1
  AND city_count = 1;
/* code provided by PROGIEZ */

585. Investments in 2016 LeetCode Solution in Java

N/A
// code provided by PROGIEZ

585. Investments in 2016 LeetCode Solution in Python

N/A
 # code by PROGIEZ

Additional Resources

Happy Coding! Keep following PROGIEZ for more updates and solutions.