Day 1 Coding Challenge

Today I have solved the first Problem of day 1.

Problem - Two sum Problem

Given an array of size n, and target variable, we need to find exactly one solution with indices of precisely two elements whose sum is equal to the target variable.

Condition - the same element should not be repeated twice.

Difficulty level - Easy

Solution - Categorize into Two solutions.

I) Brute - Force solution - We loop through every element of the array and compare with another element by looping again.

Time Complexity - O(n*n) due to two for loop.

Space Complexity - O(1)

II) Using HashMap - We can store the array value as Key and indices as value.

We are finding the complement by logic.

Complement= target - curr[element]

and store it in Map if we didn't get the complement variable.

Condition to check complement should not be equal to n[element].

Time Complexity - O(n)

Space Complexity - O(n)

In this problem, map is used to minimize time complexity, brushed up the knowledge of the map.


#coding #30daysofcodechallenge #30daysofcode #leetcode2023 #hashmap

#bruteforce #daily #consistency #problemsolving #problemsolvingskills


要查看或添加评论,请登录

Shraddha M Thakur的更多文章

  • Day 14: Coding Challenge

    Day 14: Coding Challenge

    Problem - Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10…

  • Day 13: Coding Challenge

    Day 13: Coding Challenge

    Problem - There are n children standing in a line. Each child is assigned a rating value given in the integer array…

  • Day 12: Coding Challenge

    Day 12: Coding Challenge

    Problem - There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i]. You…

  • Day 11: Coding Challenge

    Day 11: Coding Challenge

    Problem - Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the…

  • Day 10: Coding Challenge

    Day 10: Coding Challenge

    Problem - Given an array of integers citations where citations[i] is the number of citations a researcher received for…

  • Day 9: Coding Challenge

    Day 9: Coding Challenge

    Problem - You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0].

  • Day 8: Coding Challenge

    Day 8: Coding Challenge

    Problem - You are given an integer array of nums. You are initially positioned at the array's first index, and each…

  • Day 7: Coding Challenge

    Day 7: Coding Challenge

    Problem - You are given an integer array of prices where prices[i] is the price of a given stock on the ith day. On…

  • Day 6: Coding Challenge

    Day 6: Coding Challenge

    Problem - You are given an array of prices where prices[i] is the price of a given stock on the ith day. You want to…

  • Day 5: Coding Challenge

    Day 5: Coding Challenge

    Problem - Given an integer array , rotate the array to the right by steps, where is non-negative. Solution - This is a…

社区洞察

其他会员也浏览了