# Category Archives: ANDROID

## Given a dictionary of words and an input word, create a function that returns all valid step words.

By | August 29, 2024

A step word is formed by taking a given word, adding a letter, and anagramming the result. For example, starting with the word “APPLE”, you can add an “A” and anagram to get “APPEAL”. Given a dictionary of words and an input word, create a function that returns all valid step words. To solve the… Read More »

## 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 »

## A knight’s tour is a sequence of moves by a knight on a chessboard such that all squares are visited once. Given N, write a function to return the number of knight’s tours on an N by N chessboard.

By | July 30, 2024

## Let’s define a “sevenish” number to be one which is either a power of 7, or the sum of unique powers of 7.

By | April 25, 2024

The first few sevenish numbers are 1, 7, 8, 49, and so on. Create an algorithm to find the nth sevenish number. JAVA JAVASCRIPT

## Given an unsorted array of integers, find the length of the longest consecutive elements sequence.

By | April 18, 2024

For example, given [100, 4, 200, 1, 3, 2], the longest consecutive element sequence is [1, 2, 3, 4]. Return its length: 4. Algorithm should run in O(n) complexity. JAVA JAVASCRIPT PYTHON

## What are optionals in swift?

By | March 14, 2024

In Swift, optionals are a powerful feature that allows variables or constants to have a value or be nil, indicating the absence of a value. Optionals are represented using the Optional type, which is an enumeration with two cases: Some(Wrapped) to represent a value, and nil to represent the absence of a value. Here are… 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 pre-order and in-order traversals of a binary tree, write a function to reconstruct the tree.

By | January 31, 2024

For example, given the following preorder traversal: [a, b, d, e, c, f, g] And the following inorder traversal: [d, b, e, a, f, c, g] You should return the following tree: To reconstruct a binary tree from its pre-order and in-order traversals, you can use a recursive approach. The idea is to select the… Read More »

## Handling exception in Ruby

By | January 30, 2024

In Ruby, exception handling is done using the begin, rescue, else, and ensure blocks. Here’s a basic structure of a begin-rescue block: Let’s break down the components: Example with a specific exception: In this example: As with any language, it’s good practice to catch only the exceptions you expect and handle them appropriately. Avoid catching… Read More »

## How to do exception handling in python?

By | January 29, 2024

Exception handling in Python is done using the try, except, else, and finally blocks. Here’s a basic structure of a try-except block: Let’s break down the components: Example with a specific exception: In this example: You can customize exception handling based on the specific requirements of your code. It’s generally a good practice to catch… Read More »

## What are python name spaces?

By | January 27, 2024

In Python, a namespace is a container that holds a set of names (identifiers) and their corresponding objects. It serves as a mapping between names and objects, allowing you to organize and manage the scope of variables, functions, classes, and other identifiers in your code. Namespaces help avoid naming conflicts and provide a way to… 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 »

## What is inout parameter in swift?

By | January 24, 2024

In Swift, inout is a keyword used to indicate that a parameter is passed by reference and can be modified inside a function, affecting the original value outside the function. This allows a function to modify the value of the parameter and have those changes reflected in the calling scope. Here’s an example to illustrate… Read More »

## How to create a path with look in swiftUI?

By | January 22, 2024

In SwiftUI, you can create a path with a custom shape by using the Path and Shape types. Here’s a basic example of how to create a custom path with a shape in SwiftUI: In this example: You can modify the path(in:) function to create different custom shapes based on your requirements. SwiftUI provides a… Read More »

## Given a binary tree, return the level of the tree with minimum sum.

By | January 22, 2024

Java: Javascript: Python:

## Common SQL commands with example

By | January 20, 2024

Certainly! SQL (Structured Query Language) is used to interact with relational databases. Here are some common SQL commands with examples: Example: Example: Example: Example: Example: Example: Example: Example: These are just a few examples of common SQL commands. SQL is a powerful language with many features, and its usage can vary depending on the specific… Read More »

## Concurrency in Python

By | January 18, 2024

In Python, there are several ways to implement concurrency, allowing you to execute multiple tasks concurrently to improve the performance of your code. Here are some commonly used methods: Threading: Multiprocessing: Asyncio (asynchronous I/O): ThreadPoolExecutor and ProcessPoolExecutor: Choose the concurrency approach that best fits your specific use case, considering factors such as the nature of… Read More »

## How to use BlockOperation in swift?

By | January 17, 2024

In Swift, BlockOperation is a subclass of Operation that allows you to encapsulate the code you want to execute concurrently. You can use it to create operations that consist of one or more blocks of code. Here’s an example of how to use BlockOperation: In this example: The OperationQueue takes care of managing the concurrent… Read More »

## What is the difference between self and Self in iOS?

By | January 16, 2024

In iOS development with Swift, self and Self have distinct meanings and use cases. In the printValue method, self is used to explicitly refer to the value property of the current instance. 2. Self: In this example, Self is used as the return type of the createInstance method. It indicates that the method will return… 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.

## How to do navigation and data pass in swiftUI?

By | January 14, 2024

## What are the difference between UIKit and SwiftUI in iOS?

By | January 14, 2024

UIKit and SwiftUI are both UI frameworks used in iOS development, but they differ significantly in terms of design, architecture, and development approach. Here are some key differences between UIKit and SwiftUI: 1. Declarative vs Imperative 2. UI Layout 3. Code re-usability 4. Live preview 5. UI Representation 6. State management 7. Adoption and Legacy… Read More »

## How data is passed from one view to another in SwiftUI?

By | January 13, 2024

In SwiftUI, you can pass data from one view to another using the @State, @Binding, @ObservedObject, or @EnvironmentObject property wrappers. The appropriate choice depends on the nature of the data and the relationship between the views. Below are brief explanations and examples for each approach: 1. @State : Use @State to store simple values within… Read More »