I have been trying to figure this out myself. The algorithm I'm using is to colour yellow only if the count of that letter before that occurance in the guess, is less than the count of that letter in the target word.
guess: "SASSY", target: "BRASS", expect either "YYBGB" or "BYYGB". I believe your algorithm would return "YYYGB".
guess: "BRASS", target: "SASSY", expect "BBYGY"
guess: "ASSET", target: "BRASS", expect "YYYBB"
guess: "BRASS", target: "ASSET", expect "BBYYY"