CARVIEW |
Select Language
HTTP/2 200
date: Sun, 12 Oct 2025 08:42:07 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=2fd58b05af3fb60f9aa0575af4e74151c7887e808718d2bb1c189887b64a64bda%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%2216J40diavgnz7aNCTYsTKxGpQrwHuOGq%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d54d51f8eac1b0-BLR
Amazon Coding Interview - firstNonRepeatingCharacter - Pastebin.com
SHARE
TWEET

Amazon Coding Interview - firstNonRepeatingCharacter
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Purebasic 5.72
- ; Go through input string
- ; Cases
- ; Unseen character ; Pigeonhole is 0, not in ll.
- ; Seen character ; Pigeonhole is *ptr to ll element
- ; Seen again character ; Pigeonhole is 1
- ; End of input
- Procedure FirstUniqueCharacterO1n(s.s)
- NewList Found.c()
- Dim *Pigeonholes.Character(26)
- Protected L = Len(S)
- For I = 0 To L-1
- Pigeon.c = PeekC(@S+I*2) - 'a'
- P = *Pigeonholes(Pigeon)
- Select P
- Case 0 ; Not seen before
- LastElement(Found()) ; O(1)
- *Pigeonholes(Pigeon) = AddElement(Found())
- Found() = Pigeon + 'a'
- Case 1 ; Known to be a duplicate, so out of the game
- Default ; This is a new duplicate
- ChangeCurrentElement(Found(), P) ; O(1)
- DeleteElement(Found())
- *Pigeonholes(Pigeon) = 1
- EndSelect
- Next
- If FirstElement(Found()) ; O(1)
- ProcedureReturn Found()
- Else
- ProcedureReturn '_'
- EndIf
- EndProcedure
- Debug Chr(FirstUniqueCharacterO1n("abcdef")) ; a
- Debug Chr(FirstUniqueCharacterO1n("abcdefa")) ; b
- Debug Chr(FirstUniqueCharacterO1n("bbcdcdefa")) ; e
- Debug Chr(FirstUniqueCharacterO1n("aabb")) ; _
- Debug Chr(FirstUniqueCharacterO1n("")) ; _
- Debug "----------------------------------"
- Procedure FirstUniqueCharacter(s.s)
- Dim Pigeonholes.i(26)
- Protected L = Len(S)
- For I = 0 To L-1
- Pigeon.c = PeekC(@S+I*2) - 'a'
- Pigeonholes(Pigeon) + 1
- Next
- For I = 0 To L-1
- Pigeon.c = PeekC(@S+I*2) - 'a'
- If Pigeonholes(Pigeon) = 1
- ProcedureReturn Pigeon + 'a'
- EndIf
- Next
- ProcedureReturn '_'
- EndProcedure
- Debug Chr(FirstUniqueCharacter("abcdef")) ; a
- Debug Chr(FirstUniqueCharacter("abcdefa")) ; b
- Debug Chr(FirstUniqueCharacter("bbcdcdefa")) ;
- Debug Chr(FirstUniqueCharacter("aabb")) ; _
- Debug Chr(FirstUniqueCharacter("")) ; _
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐⭐⭐Instant Profit Method⭐⭐
Java | 3 min ago | 0.10 KB
-
⭐⭐⭐Free Giftcards Method⭐⭐
Java | 3 min ago | 0.10 KB
-
⭐✅ Swapzone Glitch ✅ Working ⭐⭐ U
JavaScript | 3 min ago | 0.25 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ Z
JavaScript | 3 min ago | 0.25 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ V
JavaScript | 3 min ago | 0.25 KB
-
⭐⭐⭐Swapzone.io Glitch (Working)⭐⭐
Java | 3 min ago | 0.10 KB
-
📌 Swapzone +37% glitch ⭐ P
JavaScript | 3 min ago | 0.25 KB
-
📌 Swapzone +37% glitch ⭐ P
JavaScript | 3 min ago | 0.25 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand