Merge two maps of String to Integer. If a key exists in both maps, sum their values. Return the merged map.

Examples:

Input: map1 = {a: 1, b: 2}, map2 = {b: 3, c: 4} Output: {a: 1, b: 5, c: 4} Explanation: Key b exists in both, so values are summed (2 + 3 = 5) Input: map1 = {x: 10}, map2 = {y: 20} Output: {x: 10, y: 20} Explanation: No common keys, simple merge Input: map1 = {}, map2 = {a: 1} Output: {a: 1} Explanation: One map is empty, return the non-empty map
Apex Code Editor

Welcome to Lightning Challenge!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Note

You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.