Sign In
You are coding as a Guest. Sign in with your RoleNest account to permanently track your streak, earn XP, and climb the Campus Leaderboard!
Sign In with RoleNest
🔥Scaled Dot-Product Attention (Transformer Engine)Hard
SUPER HARD PROBLEM OF THE DAY+150 XP • FAANG OA TIER

High-difficulty challenge matching authentic Google, Amazon & Uber L5 online assessment conditions.

HardAI & Machine Learning•Acceptance: 42.1%

Scaled Dot-Product Attention (Transformer Engine)

Targeted in FAANG & Tech OA:GoogleAmazonMicrosoftSwiggy
Real-World Engineering Context
The foundational core equation of modern Generative AI driving language generation, image synthesis, and multimodal reasoning.
In Transformer neural networks (GPT-4, Gemini, Claude), given query vector `Q`, key vector `K`, value vector `V`, and dimension `dk`, compute the 1D scaled dot-product attention score `softmax(Q · K / sqrt(dk)) * V`. For 1D single-token pairs, return the scalar result rounded to 4 decimal places.

Sample Test Cases

Input: [[1,0],[1,0],[10],2]
Expected: 10
Input: [[1,0],[0,1],[5],2]
Expected: 5

Constraints

  • q.length == k.length
  • 1 <= dk <= 1024
Recruiter Fast-Track ReferralVerified Candidate
Direct pipeline to Google, Amazon, Microsoft, Swiggy, & Uber recruiters
DevScore: 750/1000

Top DevScore profiles bypass resume screening filters. Every verified problem solve writes authentic proof-of-work to your profile and dispatches you directly into employer inboxes on RoleNest.