From f0ee9fb8a8a47358cddcf251803a98f55c6568a5 Mon Sep 17 00:00:00 2001 From: khushi-hura Date: Sat, 23 Nov 2024 18:17:52 +0530 Subject: [PATCH] Added solution for Leetcode Problem #15 (3Sum) in Dart - Implemented the hreeSum function to find all unique triplets that sum up to zero. - Included a time complexity of O(N^2) and space complexity of O(1). - Added unit tests with edge cases for validation. --- array/three_sum.dart | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 array/three_sum.dart diff --git a/array/three_sum.dart b/array/three_sum.dart new file mode 100644 index 0000000..625b8e8 --- /dev/null +++ b/array/three_sum.dart @@ -0,0 +1,46 @@ +//Leetcode problem no. 15: https://leetcode.com/problems/3sum/description/ +//Time Complexity: O(N^2) +//Space Complexity: O(1) + +//Input: A list of integers +//Output: A list of lists containing all those integers whose sum end up to 0 + +import 'package:test/test.dart'; + +import '../sort/heap_Sort.dart'; + +List> threeSum(List l){ + List> ans=[]; + sort(l); + for(int i=0; i0) k--; + else{ + ans.add([l[i], l[j], l[k]]); + j++; + k--; + while(j