How can I merge primary APFS partition with other empty/free space APFS partition?
You need to know the partitioning of the drive. In particular, were the free space is. The diskutil list disk0 command shows the partitions in ascending order and the size of each partition. However, this command does not show free space. The Disk Utility application does occasionally show free space but the value is often incorrect and does not show where the free space is with respect to the other partitions

So where is the free space shown? Here are a few ways to determine where the free space is.


The sudo gpt -r show /dev/disk0 command will show the logical sector blocks used by each partition. The command will also show the free space between each partition in logical sector block units. In the days of OS X, you could run this command on the boot drives. Starting with macOS, System Integrity Protection (SIP) has to be disabled to do this.
Use the diskutil info -plist disk0s# command to retrieve partition number # start and size byte values. You need to repeat the command for each partition on a drive. Next, you can compile a table similar to the output from the gpt -r show /dev/disk0 command. Basically, free space is any space not allocated to a partition, the Protected Master Boot Record (PMBR) and the GUID Partition Tables (GPT).
Write a BASH script that would automate way number 2.  A free script can be downloaded from this site. Assuming your downloads goto to the default Downloads folder, you can get the free space by entering the command shown below. Note: You do not need to enter sudo or disable SIP. 

~/Downloads/driveinfo-1.0.1/driveinfo -r disk0




  In order to add free space to a APFS container partition, the free space must reside directly below the partition.


When you deleted disk0s4, you created free space directly after disk0s3. Since disk0s3 is between disk0s2 and this free space, you can not recover the free space by using the command given in your Step 3. You could recover the free space into disk0s3 by entering the command given below.

sudo diskutil resizeVolume disk0s3 R