Author Archives: James

3 Simple ways to use Debouncer in Flutter

By | August 26, 2024

Watch Video Tutorial Using Simple Timer Create a simple debouncer class Implementation: Using ValueNotifier Implementation: Using “Simple Debouncer” package First Add easy_debouncer package in your dependencies https://pub.dev/packages/easy_debounce Source Code https://github.com/MrVipinVijayan/flutter_tutorials/tree/feat/debounce

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. Find the minimum element in O(log N) time. You may assume the array does not contain duplicates.

By | August 22, 2024

To find the minimum element in a rotated sorted array in O(log⁡N)O(\log N)O(logN) time, you can use a modified binary search approach. The key observation is that even though the array is rotated, one part of the array will still be in sorted order. By comparing elements in the middle of the array with the… Read More »

Given a 2D board of characters and a word, find if the word exists in the grid.

By | August 5, 2024

The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once. For example, given the following board: exists(board, “ABCCED”) returns true, exists(board, “SEE”) returns true, exists(board, “ABCB”) returns false. Python def exist(board, word):    if not board:        return False   … Read More »

Implement a stack API using only a heap. A stack implements the following methods:

By | January 31, 2024

Recall that a heap has the following operations: To implement a stack using only a heap, you can use a max heap and maintain a counter to ensure that the order of elements is preserved. Here’s an example implementation in Python, Java, and JavaScript using the heapq module (Python), PriorityQueue (Java), and BinaryHeap (JavaScript): Python:… Read More »

Given a string of parentheses, find the balanced string that can be produced from it using the minimum number of insertions and deletions

By | January 25, 2024

Given a string of parentheses, find the balanced string that can be produced from it using the minimum number of insertions and deletions. If there are multiple solutions, return any of them. For example, given “(()”, you could return “(())”. Given “))()(“, you could return “()()()()”. To find the balanced string with the minimum number… Read More »

Write a program to merge two binary trees. Each node in the new tree should hold a value equal to the sum of the values of the corresponding nodes of the input trees. If only one input tree has a node in a given position, the corresponding node in the new tree should match that input node.

By | January 16, 2024

Asked by SalesForce JavaScript: Java: Python: These programs define a TreeNode class and a function (mergeTrees in JavaScript, mergeTrees method in Java, and merge_trees function in Python) to merge two binary trees following the specified rules. You can adapt these examples based on your specific requirements.

Given a string, return the length of the longest palindromic subsequence in the string- Asked by Google

By | December 21, 2023

Given a string, return the length of the longest palindromic subsequence in the string. For example, given the following string: MAPTPTMTPA Return 7, since the longest palindromic subsequence in the string is APTMTPA. Recall that a subsequence of a string does not have to be contiguous! Your algorithm should run in O(n^2) time and space.… Read More »

Implement a PrefixMapSum class with the following methods

By | July 5, 2023

insert(key: str, value: int): Set a given key’s value in the map. If the key already exists, overwrite the value. sum(prefix: str): Return the sum of all values of keys that begin with a given prefix. For example, you should be able to run the following code: mapsum.insert(“columnar”, 3) assert mapsum.sum(“col”) == 3 mapsum.insert(“column”, 2)… Read More »

Problem: You are given N identical eggs and access to a building with k floors. Your task is to find the lowest floor that will cause an egg to break, if dropped from that floor.

By | July 2, 2023

You are given N identical eggs and access to a building with k floors. Your task is to find the lowest floor that will cause an egg to break, if dropped from that floor. Once an egg breaks, it cannot be dropped again. If an egg breaks when dropped from the xth floor, you can… Read More »

Create an algorithm that arranges them in order to form the largest possible integer

By | July 2, 2023

Given a list of numbers, create an algorithm that arranges them in order to form the largest possible integer. For example, given [10, 7, 76, 415], you should return 77641510. Javascript function largestNumber(nums) {  nums.sort((a, b) => {    const order1 = String(a) + String(b);    const order2 = String(b) + String(a);    return order2.localeCompare(order1); … Read More »

Problem: There are N prisoners standing in a circle, waiting to be executed…

By | June 27, 2023

There are N prisoners standing in a circle, waiting to be executed. The executions are carried out starting with the kth person, and removing every successive kth person going clockwise until there is no one left. Given N and k, write an algorithm to determine where a prisoner should stand in order to be the… Read More »

Given a sorted array, find the smallest positive integer that is not the sum of a subset of the array.

By | June 27, 2023

Java public class SmallestPositiveInteger {    public static int findSmallestPositiveInteger(int[] nums) {        int smallest = 1;        for (int num : nums) {            if (num <= smallest) {                smallest += num;            } else… Read More »

Write a program to compute the in-order traversal of a binary tree using O(1) space.

By | June 25, 2023

Python Java Javascript These implementations use the Morris Traversal algorithm to perform in-order traversal without using any additional space other than O(1). The algorithm establishes temporary links between nodes and their predecessors, allowing efficient traversal and processing of the tree nodes. Note: The code examples assume that the tree nodes have a val, left, and… Read More »

Flutter vs. React Native: Unraveling the Performance Battle

By | June 25, 2023

Introduction: When it comes to developing cross-platform mobile applications, Flutter and React Native have emerged as the two dominant frameworks. As developers seek to create high-performing apps, it’s crucial to understand the performance capabilities of each framework. In this article, we will delve into the performance aspects of Flutter and React Native, examining their strengths… Read More »

Different ways of making rounded corner images in flutter

By | June 25, 2023

Example 1: ClipRRect dartCopy codeClipRRect( borderRadius: BorderRadius.circular(10.0), child: Image.asset(‘assets/images/image.jpg’), ) In this example, the ClipRRect widget is used to clip the child Image with rounded corners. The borderRadius property defines the radius of the corners. Example 2: BoxDecoration dartCopy codeContainer( decoration: BoxDecoration( borderRadius: BorderRadius.circular(10.0), image: DecorationImage( image: AssetImage(‘assets/images/image.jpg’), fit: BoxFit.cover, ), ), ) Here, a… Read More »

Given an absolute pathname that may have . or .. as part of it, return the shortest standardized path

By | June 25, 2023

Given an absolute pathname that may have . or .. as part of it, return the shortest standardized path. For example, given “/usr/bin/../bin/./scripts/../”, return “/usr/bin/”. To obtain the shortest standardized path from an absolute pathname that may contain “.” or “..” as part of it, you can follow these steps: Here’s an example Python code… Read More »