diff --git a/submissions/KushmalArora/q1/solution.1.png b/submissions/KushmalArora/q1/solution.1.png new file mode 100644 index 0000000..6e557bd Binary files /dev/null and b/submissions/KushmalArora/q1/solution.1.png differ diff --git a/submissions/KushmalArora/q1/solution.c b/submissions/KushmalArora/q1/solution.c new file mode 100644 index 0000000..0eeb2e5 --- /dev/null +++ b/submissions/KushmalArora/q1/solution.c @@ -0,0 +1,46 @@ +/* Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. + +You may assume that each input would have exactly one solution, and you may not use the same element twice. + +You can return the answer in any order. + + + +Example 1: + +Input: nums = [2,7,11,15], target = 9 +Output: [0,1] +Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. +Example 2: + +Input: nums = [3,2,4], target = 6 +Output: [1,2] +Example 3: + +Input: nums = [3,3], target = 6 +Output: [0,1] */ + + + + + + + + +#include + +int* twoSum(int* nums, int numsSize, int target, int* returnSize){ + for (int i = 0; i < numsSize - 1; i++) { + for (int j = i + 1; j < numsSize; j++) { + if (nums[i] + nums[j] == target) { + int* result = (int*)malloc(2 * sizeof(int)); + result[0] = i; + result[1] = j; + *returnSize = 2; + return result; + } + } + } + *returnSize = 0; + return NULL; +} diff --git a/submissions/KushmalArora/q2/solution.2.png b/submissions/KushmalArora/q2/solution.2.png new file mode 100644 index 0000000..2c76f19 Binary files /dev/null and b/submissions/KushmalArora/q2/solution.2.png differ diff --git a/submissions/KushmalArora/q2/solution.c b/submissions/KushmalArora/q2/solution.c new file mode 100644 index 0000000..a801390 --- /dev/null +++ b/submissions/KushmalArora/q2/solution.c @@ -0,0 +1,54 @@ +/* Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val. + +Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things: + +Change the array nums such that the first k elements of nums contain the elements which are not equal to val. The remaining elements of nums are not important as well as the size of nums. +Return k. +Custom Judge: + +The judge will test your solution with the following code: + +int[] nums = [...]; // Input array +int val = ...; // Value to remove +int[] expectedNums = [...]; // The expected answer with correct length. + // It is sorted with no values equaling val. + +int k = removeElement(nums, val); // Calls your implementation + +assert k == expectedNums.length; +sort(nums, 0, k); // Sort the first k elements of nums +for (int i = 0; i < actualLength; i++) { + assert nums[i] == expectedNums[i]; +} +If all assertions pass, then your solution will be accepted. + + + +Example 1: + +Input: nums = [3,2,2,3], val = 3 +Output: 2, nums = [2,2,_,_] +Explanation: Your function should return k = 2, with the first two elements of nums being 2. +It does not matter what you leave beyond the returned k (hence they are underscores). +Example 2: + +Input: nums = [0,1,2,2,3,0,4,2], val = 2 +Output: 5, nums = [0,1,4,0,3,_,_,_] +Explanation: Your function should return k = 5, with the first five elements of nums containing 0, 0, 1, 3, and 4. +Note that the five elements can be returned in any order. +It does not matter what you leave beyond the returned k (hence they are underscores). */ + + + +int removeElement(int* nums, int numsSize, int val) { + int k = 0; + + for (int i = 0; i < numsSize; i++) { + if (nums[i] != val) { + nums[k] = nums[i]; + k++; + } + } + + return k; +}