instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a JavaScript code to print all possible combinations of substrings of a given string, including substrings of length 1 and the original string itself.
Example:
Input: "abc"
Output: ["a", "b", "c", "ab", "ac", "bc", "abc"]
Note:
1. The order of the output does not matter.
2. The output should not contain any dup... | codefeedback |
Write a C# code to print the first n terms of the Series 0, 1, 2, 6, 42, 1806, where each term is obtained by multiplying the previous term by the square root of a randomly generated number between 0 and 1 (inclusive). The code should also ensure that each term in the series is greater than or equal to 0 and less than ... | codefeedback |
You need to check if a variable is an integer or not, but you are not allowed to use any built-in functions or libraries for type checking. You need to implement your own algorithm to determine the variable type.
Additionally, you need to handle edge cases such as checking if the variable is a string that represents a... | codefeedback |
Write a code to generate a random password which has 10 characters and should contain at least one lowercase letter, one uppercase letter, one numeric character, and one special character from the set [!@#$%^&*()]. | codefeedback |
Using HTML and CSS, write a code to display a responsive table with four columns and five rows. The first column should display sequential numbers from 1 to 5, the second column should display random uppercase letters, the third column should display random lowercase letters, and the fourth column should display random... | codefeedback |
Suggest a way to sort a list of strings alphabetically in JavaScript using a custom sorting algorithm. The algorithm should compare the strings based on their ASCII values and should be implemented without using any built-in sorting functions or methods. | codefeedback |
Rewritten Test:
You are given a dataset containing information about the sales transactions of a company. Each row in the dataset represents a single transaction and includes the following columns: transaction_id, customer_id, product_id, quantity, and price.
Your task is to create a two-way pivot table using Python ... | codefeedback |
Implement a vector class in Python that allows for basic vector operations such as vector addition, subtraction, scalar multiplication, and dot product calculation. The vector class should also support vector normalization, which calculates the unit vector in the same direction as the original vector.
The vector class... | codefeedback |
Suggest a way to identify similar strings in JavaScript by considering the Levenshtein distance between the strings. | codefeedback |
Suggest a way to check if a given number is a palindrome number in JavaScript. Additionally, the solution should be implemented using recursion and without converting the number to a string. | codefeedback |
Create a new array containing the result of applying a given function to each element of an original array. However, the function should only be applied to elements that meet a specific condition. The condition is that the element must be a prime number.
Array: [1, 2, 3, 4, 5, 6, 7]
Function: x * 2 | codefeedback |
Create a boolean function called "is_num_even" which takes in a number and returns true if the number is even. Additionally, the function should raise a custom exception called "InvalidInputError" if the input is not a number. | codefeedback |
Write a Python class that implements a sorted list with the following methods:
1. `insert(value: int)`: Inserts the given value into the sorted list while maintaining the sorted order. The time complexity of this method should be O(log n), where n is the current number of elements in the list.
2. `remove(value: int)`... | codefeedback |
Using the following data, convert the X and Y coordinates into longitude and latitude, taking into account the curvature of the Earth and the geoid shape.
X: 83.206226
Y: 42.821810
Requirements:
1. Implement a function that converts the given X and Y coordinates into longitude and latitude.
2. The function should tak... | codefeedback |
Compute the Fibonacci series up to the following number n, but with a twist. Instead of starting with 0 and 1, start with 2 and 3. | codefeedback |
Create a function that takes in a positive integer n as input and returns an array of all the prime numbers up to n.
Requirements:
- The function should have a time complexity of O(n^1.5).
- The function should not use any external libraries or built-in functions to check for prime numbers.
- The function should handl... | codefeedback |
Write a code that finds all the prime numbers in a given range of numbers and returns the sum of the digits of each prime number found.
start_num = 1
end_num = 1000 | codefeedback |
Write a code to find the maximum length of the longest consecutive increasing subsequence in the given array, where the subsequence must include both odd and even numbers.
arr = [2, 3, 1, 10, 5, 6, 8, 7, 4, 9] | codefeedback |
Write a code to convert the provided string into an array of numbers, with the following conditions:
1. The string may contain leading or trailing spaces, remove them before converting.
2. The string may contain multiple consecutive commas (e.g. "1,,,2,3"), treat them as empty elements in the array.
3. The string may ... | codefeedback |
Implement a reverse for loop in Python that iterates over a range of numbers from 10 to 1, decrementing by 2 on each iteration. | codefeedback |
Write a function in C which will take two integer arguments and swap their values without using any temporary variables.
int x = 1;
int y = 2; | codefeedback |
Write a Python script to check if an email address is valid depending on the given conditions.
Email address: johnsmith@example.com
Check the following conditions:
1. Must contain an "@" symbol
2. Must contain a "."
3. Must have at least 6 characters
4. Must start with a letter
5. Must not contain any special character... | codefeedback |
You are given a list of people and their corresponding email addresses. Design and implement a data structure that efficiently stores this information and allows for fast retrieval of email addresses based on people's names. Additionally, the data structure should support the following operations:
1. Add a person and ... | codefeedback |
Edit the following C++ code so that it prints all prime numbers between 10 and 100 in order.
#include <iostream>
bool isPrime(int num) {
if (num <= 1) {
return false;
}
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
int main()
{
int start = 10;... | codefeedback |
Develop a code to identify the top K most commonly used words in a given text, where K is an input parameter.
The quick brown fox jumps over the lazy dog. The lazy dog jumps over the quick brown fox. | codefeedback |
Create an efficient matrix multiplication of two given matrices, where the elements of the matrices are complex numbers.
matrix1 = [[1+2j, 3+4j], [5+6j, 7+8j]]
matrix2 = [[9+10j, 11+12j], [13+14j, 15+16j]] | codefeedback |
Create a code to generate a Mulberry Tree of height n levels with the following additional requirements:
1. The height of the tree should be at least 10 levels.
2. The code should use recursion to generate the tree structure.
3. Each node of the tree should contain additional information such as its depth level and th... | codefeedback |
Generate a program to remove duplicates from an unsorted linked list while maintaining the original order of elements. The program should have a time complexity of O(n) and a space complexity of O(n), where n is the number of elements in the linked list. Additionally, the program should be able to handle linked lists w... | codefeedback |
Create a dynamic HTML page to display a navigation bar with a dropdown list that includes a list of the months of the year. Implement functionality to highlight the current month in the dropdown list and update it dynamically based on the current month of the system. Additionally, include a feature to display the curre... | codefeedback |
Create a function to evaluate a mathematical expression like "3 + 5 * 4", with the following requirements:
1. The function should support the following arithmetic operators: addition (+), subtraction (-), multiplication (*), and division (/).
2. The expression can contain multiple operators and parentheses.
3. The func... | codefeedback |
Increase the difficulty of the given programming test question by adding a more complex scenario and requiring additional synchronization mechanisms.
#Given Test#
Make the following code thread-safe by implementing mutex locks.
```cpp
#include <pthread.h>
int global_int = 0;
void* inc_func(void* arg) {
global_i... | codefeedback |
Design an algorithm to produce a binary tree from given inorder and preorder traversals. The binary tree should be constructed in such a way that the left subtree of each node contains only nodes with smaller values, and the right subtree contains only nodes with larger values.
inorder: [4,2,5,1,3,6]
preorder: [1,2,4,... | codefeedback |
Compose a function to generate a palette of random colors with the following requirements:
1. The function should generate a specified number of unique random colors.
2. Each color should be represented as a hexadecimal string, starting with a hashtag (#) followed by six characters (e.g. "#FF0000" for red).
3. The gen... | codefeedback |
Create a C# program to check if any element in an array is equal to a given number. However, you cannot use any built-in methods or functions (such as Array.IndexOf or Array.Contains) to search for the element in the array. The program should have a time complexity of O(n), where n is the size of the array. | codefeedback |
Explain the concept of a nested while loop in Python and provide an example of how it can be used in a program to solve a specific problem. | codefeedback |
Write a method to implement a Hashmap with the following parameters: key (String) and value (Integer). The method should be able to handle collisions and provide a constant time complexity for retrieval and insertion operations. | codefeedback |
Create a class called "Person" that represents a person's information. The class should have the following attributes:
- name (string): the person's name
- age (integer): the person's age
- gender (string): the person's gender
The class should have the following methods:
1. __init__(self, name): a constructor that tak... | codefeedback |
Write a function in JavaScript that will find the index of an element in a multi-dimensional array. | codefeedback |
Create a for loop that prints all even numbers from 0 to 10 (inclusive) in descending order, while also excluding the number 6 from being printed. | codefeedback |
Write a Java program to remove the duplicates in an array while maintaining the original order of elements, using only constant extra space. | codefeedback |
Write a function called "power" that takes two numbers a and b as arguments, and returns a to the power of b.
However, you are not allowed to use any built-in functions or operators for exponentiation (such as `**` or `Math.pow()`). You must implement the exponentiation algorithm manually. | codefeedback |
Create a Javascript class called "Car" that takes an argument called "year" and prints the value of "year". The class should also have a method called "getAge" that calculates and returns the age of the car in years based on the current year. Additionally, the class should have a private property called "mileage" that ... | codefeedback |
Write a regular expression to match any word that starts with "cat", ends with "dog", and contains only lowercase letters. | codefeedback |
Design an algorithm to check if a linked list is empty and return the length of the linked list.
#Additional Information#
The linked list is represented by a class `LinkedList` with the following attributes and methods:
- `head`: A reference to the first node in the linked list.
- `length()`: A method that returns the... | codefeedback |
Create a list comprehension to generate the multiples of a prime number up to a limit. The prime number should be greater than 100 and less than 1000. The limit should be a randomly generated number between 1000 and 5000. | codefeedback |
Using regex, find all the words that have a specific character at the start and end.
the words that start and end with 'a' | codefeedback |
Design a class for representing a person in Python with the following requirements:
1. The person's age must be represented as a floating-point number rounded to two decimal places.
2. The person's height must be represented in meters with a precision of three decimal places.
3. The person's weight must be represented... | codefeedback |
Using a list comprehension, create a function to give only the even numbers in a given list. Additionally, sort the resulting even numbers in ascending order. Finally, return the sum of the first three even numbers in the sorted list.
arr = [10, 7, 8, 15, 12, 14, 18, 9] | codefeedback |
Write the C++ code to print the sum of all prime factors of a given number
number = 54 | codefeedback |
Create a function in JavaScript which takes two parameters x and y and returns the multiplication of the two. However, the function should also handle cases where one or both of the parameters are not numbers. In such cases, the function should return an error message indicating the invalid input. | codefeedback |
Name the Java keyword used to define a class and explain its purpose in object-oriented programming. | codefeedback |
Use the split method to split a string based on the given delimiter and sort the resulting array in alphabetical order. The original string must contain at least 3 words separated by commas.
str = "apple,banana,orange,grapefruit,kiwi" | codefeedback |
Use a loop to find the average of all given numbers, but without using any mathematical operations such as addition, subtraction, multiplication, or division. The loop should only consist of logical operations and bitwise operators.
[1, 2, 3, 4, 5] | codefeedback |
Create a program to evaluate a postfix expression, considering only integer operands and operators +, -, *, and /. The program should also handle parentheses in the expression and throw an error if they are mismatched. | codefeedback |
Create a SQL statement to select all carts with more than 10 items in them, but exclude any carts that have a total value of items less than $100. | codefeedback |
Create a JSON object from a dictionary in Python. The dictionary contains a list of books, each with its own unique identifier, title, author, and publication year. The books are categorized into different genres, such as fiction, non-fiction, and science fiction. Additionally, each book may have multiple tags associat... | codefeedback |
Develop a program that performs basic arithmetic operations (+, -, /, *) and also includes the following additional requirements:
1. The program should take input from the user for two numbers and the arithmetic operation to be performed.
2. The program should validate the user input to ensure that the numbers are vali... | codefeedback |
Write a function to create a list with all the prime numbers in the range of 0 to 100000.
Provide a piece of erroneous code as a reference to increase misdirection:
```
def is_prime(n):
if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False
return True
def p... | codefeedback |
Given an array of integers, write a JavaScript function to remove all duplicate elements while maintaining the original order of the array.
#Revised Test Explanation#
In this revised test, the requirement to remove duplicate elements from the array remains the same. However, the additional requirement is to maintain t... | codefeedback |
Parse the following XML data using Python and calculate the average age of all the students.
<students>
<student>
<name>John</name>
<age>24</age>
</student>
<student>
<name>Jack</name>
<age>22</age>
</student>
<student>
<name>Sam</name>
<age>25</age>
... | codefeedback |
Create a program to find out the most frequent letter in a sentence.
The quick brown fox jumps over the lazy dog.
However, the program should exclude any letters that appear more than once consecutively in the sentence. For example, in the sentence "The apple is red", the letter 'p' should not be counted as it appears ... | codefeedback |
You will be given a list of integers as input. Write a program to remove the duplicates and return only the distinct values in descending order. | codefeedback |
Implement a function that takes two numbers as parameters and returns their difference.
However, the difference should only be calculated if the first number is larger than the second number. If the first number is smaller or equal to the second number, the function should return a message stating that the difference... | codefeedback |
Create an SQL query that finds the total number of customers in the "Customers" table, but only for those customers who have made at least 5 purchases. | codefeedback |
Create a JavaScript timer that runs every two seconds and displays a countdown in the console. Additionally, implement a feature that allows the user to input a specific time duration in seconds and starts the countdown from that duration. The timer should stop when it reaches 0 and display a message indicating the end... | codefeedback |
Create a function that adds two matrices of the same size and returns the resulting matrix.
The function should take two parameters:
- `matrix1` (a 2-dimensional list of integers) representing the first matrix
- `matrix2` (a 2-dimensional list of integers) representing the second matrix
The function should perform th... | codefeedback |
Write a function in Java that takes an array as input and returns an array of the same size with the elements in reverse order. However, you are not allowed to use any additional data structures or modify the original array. | codefeedback |
Create a Python function that takes an array of positive integers (1 ≤ n ≤ 1000) and returns a string that represent the mean and median of the numbers. The function should handle duplicate numbers and non-integer inputs gracefully, providing appropriate error messages. | codefeedback |
Create a program in Java that outputs a Fibonacci series of length n, where n is a positive integer greater than 1. Additionally, modify the program to handle edge cases where n is 1 or 2. If n is 1, the program should output "0". If n is 2, the program should output "0, 1". | codefeedback |
Write a function in Java that takes a String as argument and converts it to Title Case. The function should also handle special characters and ignore them while converting the string to Title Case. Additionally, the function should capitalize the first letter of each word in the string, even if the word is preceded by ... | codefeedback |
Write a SQL query to find the oldest employee in a given department, while also calculating the average age of all employees in the department. | codefeedback |
Design an algorithm to reverse a singly linked list in O(n/2) time and O(1) space. | codefeedback |
Design a Ruby program to search through an array and find the first element that satisfies the following condition: it must be a prime number and have exactly three distinct digits. | codefeedback |
Write a code snippet in C which calculates the mean of a list of numbers. However, you are not allowed to use any loops or built-in functions such as sum() or count().
int nums[] = {2, 3, 4, 5, 6}; | codefeedback |
Design a Python program to find the longest increasing subsequence in a given array. Additionally, ensure that the program does not use any built-in sorting or searching functions. | codefeedback |
Write a Java method that accepts an array of integers and returns their least common multiple.
The input array can contain up to 10^5 integers ranging from -10^9 to 10^9.
The method should have a time complexity of O(n * log(maxNum)), where n is the number of integers in the array and maxNum is the maximum absolute v... | codefeedback |
Generate a responsive HTML page with a fixed navigation bar at the top, a main content area in the middle, and a footer at the bottom using Bootstrap. Add a sticky sidebar on the left side of the main content area that scrolls along with the content. The sidebar should contain a list of links to different sections with... | codefeedback |
Write a code to find the Kth smallest element from a given array of N elements using a recursive algorithm. | codefeedback |
Rewrite the following code so that it is easier to read and understand.
def is_string_palindrome(string):
reversed_string = string[::-1]
if reversed_string == string:
return True
else:
return False | codefeedback |
Create a HTML form with 4 fields, a Name field, an Email field, a Phone number field and an Address field.
In addition to the form, add the following functionality:
1. Validate the Name field to ensure that it is not empty and contains only alphabetic characters. Display an error message if the validation fails.
2. V... | codefeedback |
Write a code snippet to find all the elements in a list that are greater than a specified number. The list can contain duplicates and the specified number can be negative. The list may also contain non-integer elements. The code should be optimized for time complexity and should not use any built-in sorting functions.
... | codefeedback |
Suppose you are designing a text editor for a specific programming language. Write a C++ code to automatically detect and remove comments from a given input string. The comments can be of two types: single-line comments that start with "//" and end with a newline character, and multi-line comments that start with "/*" ... | codefeedback |
Generate a random letter from the string provided without using any built-in random functions or libraries. The string must contain at least 10 characters. | codefeedback |
Write a TensorFlow code snippet to build a convolutional neural network with at least 5 layers and display the results of the training process. Additionally, implement data augmentation techniques such as random cropping and horizontal flipping to improve the model's performance. | codefeedback |
Generate a string representation of a binary tree with the following additional requirements:
1. Each node in the tree should be represented as a pair of parentheses containing the node's value.
2. The left subtree should be represented within the parentheses of the node, followed by a hyphen ("-"), and then the right ... | codefeedback |
Change the color of the text to blue and increase the font size to 20px.
Text: The quick brown fox | codefeedback |
Generate a random 2D array with the given dimensions.
Rows: 7
Columns: 4
Ensure that each element in the array is a unique prime number. | codefeedback |
Find a way to insert the given data into a MongoDB database using Mongoose. Ensure that each document has a unique identifier and include a timestamp indicating when each document was inserted. The data must also be validated to ensure that the name field is a string and the age field is a positive integer. Finally, im... | codefeedback |
Return the names of the customers that contain the string "ali" and are not case sensitive. | codefeedback |
Use the input to generate a loop in JavaScript to print an increasing count starting from the given number. However, you must also add a condition that skips any number that is divisible by 3. num = 5 | codefeedback |
Implement a function in JavaScript that takes an array and returns an object with the count of each element value. The input array can contain various data types including booleans, numbers, strings, and objects. The function should also handle nested arrays and objects within the input array. Additionally, the functio... | codefeedback |
Write a JavaScript code that creates an array of objects having keys "name", "age", "city", and "country". Additionally, each object must have a unique identifier key "id" consisting of a randomly generated alphanumeric string of length 10. The "name" key must contain a string of minimum length 3 and maximum length 30.... | codefeedback |
Given an array of objects, sort them in descending order according to their age. If two objects have the same age, sort them in ascending order according to their name.
array = [ {name: 'John', age: 25}, {name: 'Peter', age: 32}, {name: 'Alex', age: 21}, {name: 'Michael', age: 25} ] | codefeedback |
Write a Java program to clone an array of objects, but the objects in the array must implement a specific interface called "Cloneable". | codefeedback |
Create an algorithm to find the median of a given list of numbers. The input list may contain duplicate elements.
Input:
- A list of n integers, where n is a positive integer.
Output:
- The median of the input list. If the input list has an odd number of elements, the median is the middle element. If the input list h... | codefeedback |
Write a program that determines the language used to write a given HTML document. | codefeedback |
Design a JSON object containing Book information such as title, author, publication year, and a list of chapters. Each chapter should have a title, page count, and a list of topics covered. The JSON object should also include a list of reviews, with each review containing the reviewer's name, rating, and a comment.
A... | codefeedback |
Using this list, write a Python program to print out all the duplicate elements without using any built-in functions or data structures.
my_list = [1, 2, 3, 2, 4, 3] | codefeedback |
Create a web application that displays a table with the following columns: "ID", "First Name", and "Last Name". The table should be interactive, allowing users to sort the data based on any column in ascending or descending order. Additionally, users should be able to filter the data based on the values in any column.
... | codefeedback |
Write a method that produces a random password with the specified number of characters. The password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.