Resizing APFS container and partition
Try the commands given below.

sudo diskutil eraseVolume free none disk0s4
sudo diskutil eraseVolume free none disk0s3
sudo diskutil apfs resizeContainer disk0s2 0


The partitions with the identifiers disk0s3 and disk0s4 are of the type used for (pre)boot and/or recovery volumes. I assume these partitions are left over from some previous macOS installation(s). You no longer need these partitions since the APFS container has both (pre)boot and recovery volumes for the version of macOS you are currently using.