instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Create a function that takes in two strings and returns the number of times the first string is found within the second string, considering that the search should be case-insensitive. The function should also handle cases where the first string is empty or contains non-alphabetical characters. Additionally, the functio... | codefeedback |
Implement a Sudoku solver algorithm that takes a partially filled Sudoku grid as input and returns a solved Sudoku grid. The algorithm should be able to solve Sudoku grids of size 9x9. You can assume that the input grid will always have a valid solution. | codefeedback |
Design an algorithm to find the longest substring with no repeating characters in a given string.
Example:
Input: "abcabcbb"
Output: "abc"
Explanation: The longest substring with no repeating characters is "abc".
Input: "pwwkew"
Output: "wke"
Explanation: The longest substring with no repeating characters is "wke". ... | codefeedback |
What is a heuristic for solving the traveling salesman problem and how does it work? Provide a detailed explanation of the steps involved in applying the heuristic to find an approximate solution. | codefeedback |
Create an algorithm to sort the given list of integers in ascending order, while also ensuring that the algorithm has a time complexity of O(n log n) and uses a divide and conquer approach. The algorithm should not use any built-in sorting functions or libraries. The sorted list should be returned as the output. | codefeedback |
Write a JavaScript function that takes in an integer n and prints a specific pattern of numbers. The pattern should start with 1 and each subsequent row should contain numbers in increasing order up to n. The pattern should be printed in a zigzag manner, alternating between left to right and right to left.
For example... | codefeedback |
Modify the following array to output the sum of the even-indexed items in the array.
const array = [1, 2, 3, 4, 5, 6]; | codefeedback |
Construct a JavaScript program to sort a two-dimensional array by the sum of the absolute differences between each element in column 1 and column 2, in ascending order. If two or more sums are equal, sort those rows by the maximum value in column 3 in descending order. If the maximum values in column 3 are also equal, ... | codefeedback |
Design a function in Python which takes a list of sentences as strings and returns a dictionary containing the frequency of each word in the sentences. Each sentence may contain punctuation and special characters.
Example:
Input: ["I love apples.", "Apples are delicious!", "Do you like apples?"]
Output: {'I': 1, 'love... | codefeedback |
Create a JavaScript program which takes an array of dates and returns the average date. The average date should be rounded up to the nearest day.
Example:
Input: [2018-01-01, 2018-01-05, 2018-01-10]
Output: 2018-01-06
In the above example, the average date is calculated by summing all the dates in the array and divid... | codefeedback |
Write a function that takes in two integers and returns True if the first integer is a multiple of the second integer, and False otherwise. The function should also check if either of the integers is negative, and if so, it should raise a ValueError with the message "Both integers must be positive". Additionally, the f... | codefeedback |
Complete the program written in Java to add two numbers and print out the sum. However, you are not allowed to use any arithmetic operators (+, -, *, /) to perform the addition operation.
int a = 3;
int b = 5;
Note: You can use any other Java built-in functions or methods available. | codefeedback |
Define a Java class 'Fruits' with three instance variables - name(String), quantity(int), and colour(String). Implement the following methods:
1. A method 'getPrice' that returns the price of the fruit as a double. Assume that the price of each fruit is calculated by multiplying the quantity with a fixed price per uni... | codefeedback |
Write an SQL query to find the longest length of movies in a database called "Movies", where the length of a movie is defined as the duration in minutes. The query should exclude movies that have a rating lower than 7.0 and should only consider movies released in the past 5 years. | codefeedback |
Express the following in a for loop:
Print the squares of all the odd numbers from 1 to | codefeedback |
Construct a C++ program to find the maximum value in an array of integers using a divide and conquer approach. The array may contain negative numbers and has a size of n (1 <= n <= 10^6). The program should have a time complexity of O(nlogn) and should not use any built-in sorting functions. | codefeedback |
Write a function which takes a number n as input and returns the Fibonacci sequence up to the nth term, where n is a positive integer less than or equal to 100. The function should handle large values of n efficiently, without using recursion. | codefeedback |
Create a JavaScript module to get the current day and month, but the month should be returned as a string with the first letter capitalized. The module should also include a function to check if the current day is a weekday or a weekend day. | codefeedback |
Develop a program to remove an element from a list at the specified index, while maintaining the order of the remaining elements. The program should have a time complexity of O(n), where n is the length of the list.
my_list = [4, 5, 6, 7, 8]
index = 3
The expected output should be:
[4, 5, 6, 8] | codefeedback |
Implement a secure web service in Python to retrieve the current temperature from an external API. The service should require authentication using JWT tokens. Additionally, the service should have rate limiting in place to prevent abuse and ensure fair usage. | codefeedback |
Generate a program to perform string formatting on a given string, but only capitalize the first letter of each word. Additionally, replace all occurrences of the letter 'o' with the number '0' and append the string " - Updated!" to the end of the formatted string.
my_string = "hello, world!" | codefeedback |
Create a function which swaps the values of two list elements at specific indices and returns the modified list. The function should also handle the case when the indices are out of range. If the indices are out of range, the function should raise a custom exception with an appropriate error message. Additionally, the ... | codefeedback |
Create an algorithm to determine the maximum element in a given list. The list may contain both positive and negative integers. The maximum element must be found in O(n) time complexity. Additionally, the algorithm should not use any built-in functions or methods that directly provide the maximum element in a list. The... | codefeedback |
Design a responsive web page in HTML5 with a heading, a paragraph, a button, and a form that contains input fields for name, email, and a drop-down menu for selecting a country. Implement client-side validation for all input fields and display appropriate error messages if any field is left empty or if the email format... | codefeedback |
Create a function in Java to check if the sum of two given positive integers is greater than two times the second number. The function should also handle the case where either of the given numbers is negative and return false in such cases. Additionally, the function should handle the case where the sum of the two numb... | codefeedback |
Create a program to return all the prime numbers under the nth number, where n is a positive integer greater than 1.
To solve this problem, you can use the Sieve of Eratosthenes algorithm. This algorithm involves creating a boolean array of size n and initializing all the entries as true. Then, starting from 2, for ev... | codefeedback |
Write a shell script to list the contents of a given folder and its subfolders, including all the files and directories within them. The script should display the complete path for each item listed.
Additional requirements:
1. The script should handle folders with spaces in their names correctly.
2. The script should ... | codefeedback |
How would you create a function to calculate the factorial of a given number in Python? Additionally, you should optimize the function to handle large numbers and provide an efficient solution with a time complexity of O(n). | codefeedback |
Implement a function in C++ to return the inverse of a given 2-D array.
Sample Input:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Sample Output:
[[-3, 2, -1], [6, -5, 4], [-3, 2, -1]] | codefeedback |
Generate prime numbers between two given numbers where the sum of the digits of each prime number is a perfect square.
start = 8
end = 20 | codefeedback |
Given a list of dates, print the number of days in each month for each date in the list. | codefeedback |
How do you set up a YAML list with a specific size and initialize all the elements with a default value? | codefeedback |
Create a function to raise a given number to the Nth power. The number can be a decimal number and the exponent can be a negative number. The function should handle these cases as well. The function should have a time complexity of O(log N) or better. | codefeedback |
Create a SQL query to return every column from a table named 'books' where the title includes the word 'Ember' and the author's name starts with the letter 'J'. | codefeedback |
Split a list into two parts, where the first part contains odd numbers and the second part contains even numbers. The list should be split in such a way that the first part maintains the relative order of odd numbers and the second part maintains the relative order of even numbers. If there are no odd numbers or no eve... | codefeedback |
Edit the following JavaScript code to create an array of only the even numbers from the given array. The code should also sort the resulting array in descending order. [5, 12, 7, 23, 10] | codefeedback |
Generate HTML code to create a secure login page with a username and password field, ensuring that the password field is masked and has a minimum length of 8 characters. Additionally, include a "forgot password" link that redirects to a password recovery page and implement server-side validation to prevent brute force ... | codefeedback |
Summarize the given article using the Gensim summarizer and exclude certain sentences containing specific keywords provided by the user. Additionally, the summary should not exceed a maximum word limit specified by the user. | codefeedback |
Extend the following code to ensure that the array of numbers is sorted using insertion sort.
Constraints:
- The array can contain duplicate numbers.
- The length of the array should be at least 10.
arr = [9, 5, 7, 3, 2, 8, 1, 6, 4, 10]
#Rewritten Test# | codefeedback |
Describe the purpose of a hash table and provide a detailed explanation of how it handles collisions and ensures efficient retrieval of data. | codefeedback |
Write a Java code to take a string as input and return the number of unique words present in it. Consider that words are separated by one or more spaces and punctuation marks should be ignored.
Example:
Input: "Hello, how are you? How are you doing today?"
Output: 6 (Hello, how, are, you, doing, today)
Note:
- Words ... | codefeedback |
Write a code snippet to print a right aligned triangle of asterisks.
Length: 10
#Erroneous Code Reference#
The following code snippet prints a left aligned triangle of asterisks instead of a right aligned triangle.
```
for i in range(1, 6):
print('*' * i)
``` | codefeedback |
Remove all duplicated characters from a string and return the modified string. If a character appears multiple times in a row, only the first occurrence should be kept. If the string is empty or contains no duplicated characters, return the original string.
For example:
Input: "abcabcabc"
Output: "abc"
Input: "hello"... | codefeedback |
What are the steps involved in training a Naive Bayes classifier and how does it make predictions on new data? | codefeedback |
Parse the following HTML code to get all the hyperlinks in the page. However, you should only consider hyperlinks with an "href" attribute and skip any hyperlinks without it. Additionally, the program should also remove any duplicate hyperlinks and return a sorted list of unique hyperlinks. | codefeedback |
Compare and contrast SQL and NoSQL databases, highlighting their advantages and disadvantages in terms of data modeling, scalability, performance, and querying capabilities. Additionally, discuss the use cases and industries where each type of database is most commonly used. | codefeedback |
Construct a JavaScript program to find all the prime numbers within a range of numbers, where the range is provided as an array of two integers.
range = [2, 10]
Sample Output:
[2, 3, 5, 7]
Note:
- You should handle cases where the range is empty or where the range only contains one number.
- You should handle cases ... | codefeedback |
Generate a multiplication table for a given number in JavaScript, but exclude the multiples of 3.
n = 5; | codefeedback |
Train a deep convolutional neural network (CNN) model in PyTorch to classify the given dataset of 10,000 images into 4 classes with at least 90% accuracy. The model should have a minimum of 5 layers, including convolutional, pooling, and fully connected layers. Additionally, the model should use a regularization techni... | codefeedback |
What are the advantages and disadvantages of using an exception handler in programming? | codefeedback |
Mark the output of the following two lines of C++ code, ensuring that the final result is a prime number:
int a = 10;
int b = ++a + ++a; | codefeedback |
Explain the concept of a stack overflow error and discuss how a programmer can debug and fix it. | codefeedback |
Build a function to convert an adjacency matrix into an adjacency list while also considering weighted edges. The function should take an additional matrix as input, representing the weights of each edge. The weights matrix should have the same dimensions as the adjacency matrix. | codefeedback |
How can a programmer optimize a code that calculates the sum of an array to improve its performance while ensuring that the code is also readable and maintainable? | codefeedback |
Explain the differences between a Dictionary and a List in Python and when to use each data structure. Provide code examples to support your explanation. | codefeedback |
Find the number of unique subsets of a given set, where each subset must contain at least one odd number.
given_set = {1, 2, 3, 4, 5, 6, 7, 8, 9} | codefeedback |
Design a CSS class to center align a div with class name "main" both horizontally and vertically. The div should also have a maximum width of 500px and a minimum height of 200px. Additionally, the center aligned div should have a 2px solid border with a color of #333 and a background color of #f1f1f1. | codefeedback |
Implement an algorithm in C++ for finding the kth largest number in an array, where k is an input parameter. The array may contain both positive and negative integers. The function should return the kth largest number in the array.
Example:
Input: arr[] = {3, 7, 1, -2, 9, 5}, k = 3
Output: 5
Note: You can assume tha... | codefeedback |
Write a MySQL query to create a database called "flower_shop" and create the following tables within the database:
1. Table: "flowers"
- Columns:
- flower_id (INT, Primary Key, Auto Increment)
- name (VARCHAR(50))
- color (VARCHAR(20))
- price (DECIMAL(8, 2))
- quantity (INT)
2. Table: "c... | codefeedback |
Create a query in SQL to find the record with id 2 from the table "users" and update the "name" column to "John Doe". | codefeedback |
Build a quickly-sortable tree from a given array.
Array = [3, 8, 4, 5, 2, 10, 7]
Additional Instructions:
1. Implement the sorting algorithm yourself instead of using built-in sort functions.
2. The tree should be built in a way that allows for efficient insertion and retrieval of elements.
3. The tree should be sorte... | codefeedback |
Given an array of numbers, find the longest increasing sequence in the array. However, you are only allowed to use a single loop to solve the problem. Array = [2, 3, 5, 4, 7, 9, 6, 8] | codefeedback |
Implement a function to perform in-place array rotation.
arr = [1, 2, 3, 4, 5]
rotation = 2
Reference Erroneous Code:
```
def rotate_array(arr, rotation):
for i in range(rotation):
arr.append(arr[i])
del arr[:rotation]
return arr
```
In the given rewritten test, the reference erroneous code is pro... | codefeedback |
Design a class for a grocery store inventory management system that supports the following functionalities:
1. Add a new product to the inventory.
2. Remove a product from the inventory.
3. Update the quantity of a product in the inventory.
4. Get the quantity of a product in the inventory.
5. Get the total value of th... | codefeedback |
Write a function that returns the number of times an element appears in a sorted array. The function should only use a single loop and have a time complexity of O(log n), where n is the size of the array. The array will contain at most 10^6 elements and the element to search for will be a positive integer between 1 and... | codefeedback |
Given two strings, find the minimum number of operations required to convert one string to the other using the following operations:
- Insert a character
- Delete a character
- Replace a character
String 1 = "horse"
String 2 = "ros"
Example:
Input: "horse", "ros"
Output: 3
Explanation:
To convert "horse" to "ros", ... | codefeedback |
Write a function that takes two strings and determines if the first string is one character away from the second string. The function should handle case sensitivity and whitespace. Additionally, the function should return False if the two strings have a difference in length greater than 1. String 1 = "cat", String 2 = ... | codefeedback |
Identify the data structure most suitable for storing 100,000 unique integers. Additionally, the data structure should support fast lookup, insertion, and deletion operations with a time complexity of O(log n) or better. | codefeedback |
Write a C++ function that takes a string as input and removes all special characters from it. Special characters include any non-alphanumeric characters except whitespace. The function should modify the original string and return it. Additionally, the function should also count the number of occurrences of each alphabe... | codefeedback |
Develop a Django application to store car model, make, year, and price in the database.
Requirements:
1. The application should have a user interface to add, view, edit, and delete car records.
2. Each car record should have the following fields: model (string), make (string), year (integer), and price (float).
3. The... | codefeedback |
Create a Regex in JavaScript to extract all words of length 6 or more that start with a vowel from a sentence.
Sentence = "This is a sample sentence with some words of length 6 or more" | codefeedback |
Write a function to traverse a binary search tree using depth-first search algorithm in Java, without using recursion. | codefeedback |
Explain the process of linear search, ensuring that the search is case-sensitive and the input array must be sorted in ascending order, in a few sentences. | codefeedback |
Implement a web application that allows users to create and manage a personal to-do list. The application should have the following functionalities:
1. Users should be able to add new tasks to their to-do list.
2. Users should be able to mark tasks as completed.
3. Users should be able to delete tasks from their to-do ... | codefeedback |
How would you test a Turing machine and identify any potential limitations or issues in its functionality? | codefeedback |
Write a code to generate a random password using the random library of Python. The password should satisfy the following requirements:
- The length of the password should be 8 characters.
- The password should contain at least one uppercase letter, one lowercase letter, one digit, and one special character (!@#$%^&*).
... | codefeedback |
Write a Java program to generate a Fibonacci series up to N numbers. The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones, starting from 0 and 1. For example, the Fibonacci series up to 10 numbers is: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.
Your program should take an input N f... | codefeedback |
Construct an algorithm to detect a cycle in a linked list, but you are not allowed to use additional space. | codefeedback |
Write a function to determine the largest prime number in an unordered array.
array = [6, 8, 1, 3, 4] | codefeedback |
Return the maximum number of 256-bit numbers that fit in a 1GB RAM, while taking into account the size overhead of the programming language's data structures and memory allocation. Additionally, consider any potential alignment or padding requirements for the 256-bit numbers in memory. | codefeedback |
Create a new vector of size 5 filled with random integers between 1 and 10 (inclusive). | codefeedback |
Build a program to print the frequency of characters in an input string, considering only alphabets (a-z, A-Z). The input string may contain spaces, special characters, and numbers.
Example input_string: "abc@!123 ABCabc"
The program should ignore spaces, special characters, and numbers while calculating the frequency... | codefeedback |
Write a function in Java to delete all numbers from an array which are divisible by three and are even, and then sort the remaining numbers in ascending order.
Additional requirement: The function should have a time complexity of O(nlogn), where n is the size of the input array.
Original array: [1, 2, 3, 4, 5, 6, 7, 8,... | codefeedback |
Write a function for removing duplicate values from an array, without using any built-in methods or data structures (such as sets or dictionaries) to store unique values. | codefeedback |
Implement a function that takes in two strings and returns a boolean value indicating whether the first string is lexicographically greater than the second string. The comparison should be case-sensitive. You are not allowed to use any built-in functions or libraries for string comparison.
#Example Usage#
is_greater("... | codefeedback |
Identify the correct loop structure to traverse through a list of numbers in reverse order. | codefeedback |
Given an array of strings, generate an object with the strings as keys and the length of each string as values. The generated object should only include strings that have a length greater than or equal to 3 characters. Additionally, the generated object should not include any strings that contain special characters or ... | codefeedback |
Write a program that takes in a list of integers and returns the smallest positive integer that is not present in the list.
Constraints:
- The input list can contain up to 100,000 integers.
- The input list can contain positive and negative integers.
- The program should have a time complexity of O(n), where n is the ... | codefeedback |
Create a 2D array with n columns and m rows and fill it with random numbers. Additionally, write a function that calculates the average of each row in the array and returns the row with the highest average value. Print out the row number and its corresponding average value.
Rows: 10, Columns: 12 | codefeedback |
Acquire the necessary data to apply linear regression on the following problem statement
Predict the average property value in a particular city given population density, housing costs, average income, and the crime rate. | codefeedback |
Design a program to detect an infinite loop in a given program, without using any loops or recursion. | codefeedback |
Translate the following sentiment analysis model written in Python to JavaScript. Additionally, add a piece of erroneous code as a reference to increase misdirection.
model = tf.keras.models.Sequential([
tf.keras.layers.Dense(128, activation='relu', input_shape=(train_data.shape[1],)),
tf.keras.layers.Dense(2, act... | codefeedback |
Write a MySQL query to join 3 tables.
Table1: users
ID | Name | Email
Table2: orders
OrderID | UserID | OrderDate
Table3: products
ProductID | ProductName | Price
The query should retrieve the following information:
- User's name and email from the users table
- Order date from the orders table
- Product name and pr... | codefeedback |
Describe a good object-oriented design approach for the following problem statement:
Design an application that provides a way for users to store and access their banking records, including functionality for creating accounts, making deposits and withdrawals, transferring funds between accounts, and generating account ... | codefeedback |
Create a Django application to serve an API endpoint
The API endpoint should take an ID and return a user's name, age, and a list of their previous addresses.
The user's name and age should be stored in a database table called "users". Each user should have a unique ID, name, and age.
The user's previous addresses s... | codefeedback |
Create a JavaScript program that updates the navigation menu based on user preferences. The program should allow users to customize their navigation menu by adding, removing, or rearranging menu items. The program should also support multiple user profiles, where each profile can have its own set of preferences for the... | codefeedback |
Create a CSS class named "blue-bg" and style it to give any HTML element a blue background color. However, the class should only apply to div elements that have a minimum width of 200 pixels and a maximum width of 500 pixels. Additionally, the class should only be applied to elements that have the "highlight" class as ... | codefeedback |
Create a web application using Flask, which provides a search form that can handle a large dataset of over 1 million records efficiently and returns results in real-time. The search functionality should support fuzzy search, where users can find results even if they have typos or minor errors in their search query. Add... | codefeedback |
Write an SQL query to select the "name", "salary", and "department" columns of all employees who have a salary greater than the average salary of their respective department. Additionally, order the results in descending order of salary.
Table name: employees | codefeedback |
Design a data structure for a deck of cards that supports the following operations:
1. Shuffle: Randomly rearranges the order of the cards in the deck.
2. Draw: Removes and returns the top card from the deck.
3. Insert: Inserts a new card at a specific position in the deck.
4. Remove: Removes a specific card from the d... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.