Skip to content

Instantly share code, notes, and snippets.

@Taremeh
Last active July 18, 2022 16:47
Show Gist options
  • Save Taremeh/f7ea96c6610d83aad7d5d2e5db955e53 to your computer and use it in GitHub Desktop.
Save Taremeh/f7ea96c6610d83aad7d5d2e5db955e53 to your computer and use it in GitHub Desktop.
Automatically create Images of Code Snippets using Selenium + Carbon
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Taremeh
Copy link
Author

Taremeh commented Jul 18, 2022

Sample Code Snippet:

# https://raw.githubusercontent.com/TheAlgorithms/Python/master/data_structures/binary_tree/fenwick_tree.py
class FenwickTree:
    def __init__(self, SIZE):  # create fenwick tree with size SIZE
        self.Size = SIZE
        self.ft = [0 for i in range(0, SIZE)]

    def update(self, i, val):  # update data (adding) in index i in O(lg N)
        while i < self.Size:
            self.ft[i] += val
            i += i & (-i)

    def query(self, i):  # query cumulative data from index 0 to i in O(lg N)
        ret = 0
        while i > 0:
            ret += self.ft[i]
            i -= i & (-i)
        return ret

# # # # # # # # # # # #
# # # TASK (EASY) # # #
# # # # # # # # # # # #

# What will be printed if you run the following code?

if __name__ == "__main__":
    f = FenwickTree(3)
    f.update(1, 10)
    f.update(2, 20)
    print(f.query(2))

# Solution (stdout):
#
# 20
# 20
# 24
# 20
# 15

Generated Images:

1. Code Image

10-142-code

2. Task Image

10-142-task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment