From 305fc5f1f16d549064bbab168ce972bc0ac7f081 Mon Sep 17 00:00:00 2001 From: Nikhil_sai <118588515+nikhilsaimarri@users.noreply.github.com> Date: Tue, 21 Oct 2025 22:51:10 -0500 Subject: [PATCH 1/2] Add productExceptSelf method in Solution class Implement productExceptSelf method to calculate the product of array elements except self. --- Product except itself | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Product except itself diff --git a/Product except itself b/Product except itself new file mode 100644 index 00000000..005e3599 --- /dev/null +++ b/Product except itself @@ -0,0 +1,24 @@ +class Solution { + public int[] productExceptSelf(int[] nums) { + int n = nums.length; + + int[] result = new int[n]; + + int rp = 1; + result[0] = 1; + + for(int i=1; i=0; i--){ // right pass + rp = rp*nums[i+1]; + result[i] = result[i] * rp; + } + + return result; + } +} From 0aa963a5196fcd328cfa256059d6bee872ebc16f Mon Sep 17 00:00:00 2001 From: Nikhil_sai <118588515+nikhilsaimarri@users.noreply.github.com> Date: Tue, 21 Oct 2025 22:53:20 -0500 Subject: [PATCH 2/2] Add diagonal traversal method in Solution class Implement diagonal traversal of a matrix. --- Diagonal traverse | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Diagonal traverse diff --git a/Diagonal traverse b/Diagonal traverse new file mode 100644 index 00000000..47e19438 --- /dev/null +++ b/Diagonal traverse @@ -0,0 +1,43 @@ +class Solution { + public int[] findDiagonalOrder(int[][] mat) { + int m = mat.length; + int n = mat[0].length; + + int[] result = new int[m*n]; + int r = 0, c = 0; + + boolean dir = true; + + for(int i = 0; i < m * n; i++) { + result[i] = mat[r][c]; + + if(dir) { + if(c == n - 1) { + r++; + dir = false; + } + else if(r == 0) { + c++; + dir = false; + } + else { + r--; c++; + } + } else { + if(r == m - 1) { + c++; + dir = true; + } + else if(c == 0) { + r++; + dir = true; + } + else { + r++; c--; + } + } + } + + return result; + } +}