You have hybrid partitioning. The question you have linked to does not. An indicator of hybrid partitioning is the output of the following warning message from the gpt command.
Suspicious MBR at sector 0
When a GUID partitioning is being used, there are two tables. The first is the MBR (Master Boot Record) partition table located at sector 0. This is followed by the GPT (GUID Partition Table) which occupies several sectors. When hybrid partition is being used, one or more entries in the GPT are duplicated in the MBR partition table. The gpt remove command can only remove a duplicate entry from the GPT. This means the other duplicate in the MBR partition table remains. The gpt add command will not add an entry to the GPT, if this entry overlaps an entry in the GPT or the MBR partition table. In your case, the duplicate entry in the MBR partition table was indicated by the following line output from the gpt -r show disk0 command.
409640 1318255112 2 MBR part 218
Hybrid partitioning is required, if you need to BIOS boot an operating system on an older Macs that has a BIOS. For example, older Macs may need to BIOS boot certain versions of Windows. Below are answers which depend on whether Windows is installed.
Note: Since you will be booting to macOS Recovery from a flash drive, you probably can omit sudo from the commands given below. With older versions of macOS and OS X, the -f option for the gpt command may not be available. If the -f option is omitted, then you may need to enter the command diskutil unmountdisk disk0 before entering the gpt command.
Answer When Windows Is Not Installed
Since you only have macOS installed, you do not need hybrid partitioning. Below are the steps you can take to remove hybrid partitioning from disk0.
Enter the following command to edit the MBR partition table.
sudo fdisk -e /dev/disk0
When using the above command, the following warning messages can be ignored.
fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory
Device could not be accessed exclusively.
A reboot will be needed for changes to take effect.
This is an interactive command. Below are the values to enter into this command. A blank line indicates you are to accept the default values by pressing the return key. If you make a mistake, you can press the control+C key combination to exit fdisk without saving any changes.
auto hfs
edit 1
0
edit 1
ee
1
quit
yes
When finish, the sudo fdisk /dev/disk0 should produce the following output
Disk: /dev/disk0 geometry: 91201/255/63 [1465149168 sectors]
Signature: 0xAA55
Starting Ending
#: id cyl hd sec - cyl hd sec [ start - size]
------------------------------------------------------------------------
1: EE 0 0 2 - 1023 254 63 [ 1 - 1465149167] <Unknown ID>
2: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
3: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
4: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
After removing the hybrid partitioning, you should be able to enter one of the next three commands to add back in the macOS partition.
Below is the first possible command for adding the macOS partition back into the GPT. If you are using Core Storage, encryption or APFS, then skip this command.
sudo gpt -f add -i 2 -b 409640 -s 1318255112 -t hfs disk0
If you are not using APFS and you are using encryption and/or Core Storage, then you should use command given below.
sudo gpt -f add -i 2 -b 409640 -s 1318255112 -t 53746F72-6167-11AA-AA11-00306543ECAC disk0
If you are using APFS, then you should substitute the command given below.
sudo gpt -f add -i 2 -b 409640 -s 1318255112 -t apfs disk0
Answer When Windows Is Installed
2011 model Macs require Windows to be installed to BIOS boot. This means you need to keep hybrid partitioning. In this case, the instructions below will remove the duplicate entry from the MBR partition table, then add this entry back into both the GPT and MBR partition table.
The command given below removes the duplicate entry from the MBR partition table.
sudo fdisk -e /dev/disk0
This is an interactive command. Below are the values to enter into this command. If you make a mistake, you can press the control+C key combination to exit fdisk without saving any changes.
edit 2
0
quit
yes
You should be able to enter one of the next three commands to add back in the macOS partition.
Below is the first possible command for adding the macOS partition back into the GPT. If you are using Core Storage, encryption or APFS, then skip this command.
sudo gpt -f add -i 2 -b 409640 -s 1318255112 -t hfs disk0
If you are not using APFS and you are using encryption and/or Core Storage, then you should use command given below.
sudo gpt -f add -i 2 -b 409640 -s 1318255112 -t 53746F72-6167-11AA-AA11-00306543ECAC disk0
If you are using APFS, then you should substitute the command given below.
sudo gpt -f add -i 2 -b 409640 -s 1318255112 -t apfs disk0
Below adds the duplicate back into the MBR partition table.
sudo fdisk -e /dev/disk0
The interactive entries for the above command are given below.
edit 2
af
n
409640
1318255112
quit
yes
Fixing the macOS Boot Partition
The partition with an index of 3 has a GPT partition type of 48465300-0000-11AA-AA11-00306543ECAC. This should be 426F6F74-0000-11AA-AA11-00306543ECAC. You need to change this the same way you did for the partition with an index of 2.
The remove command is given below.
sudo gpt -f remove -i 3 disk0
The add command is given below.
sudo gpt -f add -i 3 -b 1318664752 -s 1269536 -t 426F6F74-0000-11AA-AA11-00306543ECAC disk0