class Vector3D
x, y, z
constructor(x, y, z)
this.x := x
this.y := y
this.z := z
method add(other)
this.x := this.x + other.x
this.y := this.y + other.y
this.z := this.z + other.z
method isZero()
return (this.x = 0 AND this.y = 0 AND this.z = 0)
function check_equilibrium(n, forces)
sum := new Vector3D(0, 0, 0)
for each force in forces
sum.add(force)
if sum.isZero() then
return "YES"
else
return "NO"
``` . The time complexity is $O(n)$ where $n$ is the number of forces.
C++20 sections · 1024 units
Open in CourseYoung Physicist - Implementation
Complete solution