PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Intersystems

Predict output when iterating ordered keys

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of ordered maps, iteration semantics, reverse traversal and accumulation of values in code. It is commonly asked in Coding & Algorithms interviews to test the ability to reason about iteration order, sentinel return values and summation behavior, and it examines practical application of data-structure semantics rather than purely abstract theory.

  • medium
  • Intersystems
  • Coding & Algorithms
  • Software Engineer

Predict output when iterating ordered keys

Company: Intersystems

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Assume you have a data structure `global_var[a][time]` that behaves like an **ordered map**: - Keys (`time`) are kept in **sorted ascending** order. - `order(map, key, dir)` returns the **next key** after `key`. - If `dir = 1`, it returns the next higher key. - If `dir = -1`, it returns the next lower key. - If `key = ""`, then `order(map, "", 1)` returns the **smallest** key and `order(map, "", -1)` returns the **largest** key. - If there is no next key, it returns `""`. Given: ``` global_var["A"] = { 2: 5, 4: 6, 9: 1, 15: 3 } ``` And this pseudocode: ```text time = "" sum = 0 visited = [] while true: time = order(global_var["A"], time, -1) if time == "": break visited.append(time) sum = sum + global_var["A"][time] print(visited) print(sum) ``` **Task:** What does the program print (the `visited` list and `sum`)?

Quick Answer: This question evaluates understanding of ordered maps, iteration semantics, reverse traversal and accumulation of values in code. It is commonly asked in Coding & Algorithms interviews to test the ability to reason about iteration order, sentinel return values and summation behavior, and it examines practical application of data-structure semantics rather than purely abstract theory.

Related Interview Questions

  • Measure 45 minutes with two ropes - Intersystems (medium)
  • Find the longest palindromic substring - Intersystems (easy)
Intersystems logo
Intersystems
Feb 12, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0
Loading...

Assume you have a data structure global_var[a][time] that behaves like an ordered map:

  • Keys ( time ) are kept in sorted ascending order.
  • order(map, key, dir) returns the next key after key .
    • If dir = 1 , it returns the next higher key.
    • If dir = -1 , it returns the next lower key.
    • If key = "" , then order(map, "", 1) returns the smallest key and order(map, "", -1) returns the largest key.
    • If there is no next key, it returns "" .

Given:

global_var["A"] = {
  2:  5,
  4:  6,
  9:  1,
  15: 3
}

And this pseudocode:

time = ""
sum = 0
visited = []

while true:
  time = order(global_var["A"], time, -1)
  if time == "":
    break
  visited.append(time)
  sum = sum + global_var["A"][time]

print(visited)
print(sum)

Task: What does the program print (the visited list and sum)?

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Intersystems•More Software Engineer•Intersystems Software Engineer•Intersystems Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.