Neet Code Problems

From ZCubes Wiki
Revision as of 23:36, 11 September 2024 by Joseph (talk | contribs) (→‎z^3 Solution)
Jump to navigation Jump to search

Neet Code Solutions

Thinking in z^3

This is a quick introduction to the z^3 language (pronounced as "zcubes language").

ZCubes Language (z^3) is an easy to write, natural to read, omni-functional language.

Learn z^3 Language in detail by clicking this link.

Introduction

Following are z^3 Solutions to YouTube Code Report Channel Videos. To learn how to code in ZCubes language, please visit [https://coding.zcubes.com]. ZCubes Web Platform can be started in Code Mode at [https://code.zcubes.com].

Problems and Solutions

Products of Array Discluding Self

Video: https://www.youtube.com/watch?v=bNvIQI2wAjk [I ❤ APL and Haskell #2 ]

z^3 Solution

a=[-1,-2,-3,4,3,2,1];
∏±a

Gives answer -1

∏ is Product, ± is SIGN function. APL has 3 characters it its solution (selected as the best solution in the video because of its brevity). Interesting that the solution with z^3 has even less characters, just 2.

Powerful Solution to Indexing Problem (1 character in z^3 vs 3 in APL)

Video: https://www.youtube.com/watch?v=ctbGMuakpHk [Product of Array Except Self - Leetcode 238 - Python]

Problem Description:

Given an integer array nums, return an array output where output[i] is the product of all the elements of nums except nums[i].

Each product is guaranteed to fit in a 32-bit integer.

Follow-up: Could you solve it in O ( n ) O(n) time without using the division operation?

Example 1:

Input: nums = [1,2,4,6]

Output: [48,24,12,8] Example 2:

Input: nums = [-1,0,1,2,3]

Output: [0,-6,0,0,0]

z^3 Solution

n=[1,2,4,6];
n⪥n≡∏

Gives answer

24
12
48
24


n=[-1,1,0,-3,3];
n⪥n≡∏

Gives answer:


0
0
0
0
0


Notes: ⪥ is the .around operator on an array, which takes one or more indices from the second argument to give you an array except that index. ≡∏ Product (∏) conducted by row (≡)

n⪥n can be written as n.around(n) also.

Other Interesting Solutions

See Related